#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory.h>

using namespace std;

const long long maxn = 222222;
vector<long long> forbid;
bool isForbid[maxn];
long long n, m;
vector<long long> divisors;

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

long long binpow(long long a, long long b, long long mod) {
	if (b == 0) {
		return 1;
	}
	else if (b % 2 == 0) {
		return binpow((a * a) % mod, b / 2, mod);
	}
	else {
		return (a * binpow(a, b - 1, mod)) % mod;
	}
}

long long f[maxn];

long long go(long long p) {
	if (f[p] != -1) {
		return f[p];
	}

	long long cnt = 0;
	for (long long i = 1; i < p; i++) {
		if (gcd(i, p) == 1) {
			long long want = m / p * i;
			if (!isForbid[want]) {
				cnt++;
			}
		}
	}
	long long ans = 0;

	for (long long i = 0; i < divisors.size(); i++) {
		if (p % divisors[i] != 0) {
			continue;
		}
		long long next = p / divisors[i];

		ans = max(ans, go(next));
	}

	ans += cnt;

	f[p] = ans;
	return f[p];
}

int main() {
	ios_base::sync_with_stdio(false);
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");

	memset(f, -1, sizeof(f));
	cin >> n >> m;
	for (long long i = 0; i < n; i++) {
		long long q;
		cin >> q;
		forbid.push_back(q);
		isForbid[q] = true;
	}

	long long temp = m;
	for (long long i = 2; i * i <= temp; i++) {
		if (temp % i == 0) {
			divisors.push_back(i);
			while (temp % i == 0) {
				temp /= i;
			}
		}
	}
	if (temp > 1) {
		divisors.push_back(temp);
	}

	long long ans = go(m);

	vector<long long> nums;

	long long cur = m;
	long long lastMult = 1;
	long long globalInverse = 1;
	while (cur > 1) {
		long long curAdded = 0;
		long long phi = 0;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				phi++;
			}
		}
		long long curMul = 1;
		bool firstAdd = true;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				if (!isForbid[m / cur * i]) {
					if (firstAdd) {
						nums.push_back(lastMult * i);
						firstAdd = false;
					}
					else {
						nums.push_back(((binpow(curMul, phi - 1, cur) * i)) % m);
					}
					curMul = i;
					curAdded++;
				}
			}
		}
		globalInverse *= binpow(curMul, phi - 1, cur);
		globalInverse %= cur;
		for (long long i = 0; i < divisors.size(); i++) {
			if (cur % divisors[i] != 0) {
				continue;
			}
			long long next = cur / divisors[i];
			if (f[cur] == curAdded + f[next]) {
				cur = next;
				lastMult = divisors[i];
				break;
			}
		}
	}

	if (!isForbid[0]) {
		ans++;
		nums.push_back(0);
	}

	cout << ans << endl;
	for (long long i = 0; i < nums.size(); i++) {
		cout << nums[i] << " ";
	}

	//system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory.h>

using namespace std;

const long long maxn = 222222;
vector<long long> forbid;
bool isForbid[maxn];
long long n, m;
vector<long long> divisors;

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

long long binpow(long long a, long long b, long long mod) {
	if (b == 0) {
		return 1;
	}
	else if (b % 2 == 0) {
		return binpow((a * a) % mod, b / 2, mod);
	}
	else {
		return (a * binpow(a, b - 1, mod)) % mod;
	}
}

long long f[maxn];

long long go(long long p) {
	if (f[p] != -1) {
		return f[p];
	}

	long long cnt = 0;
	for (long long i = 1; i < p; i++) {
		if (gcd(i, p) == 1) {
			long long want = m / p * i;
			if (!isForbid[want]) {
				cnt++;
			}
		}
	}
	long long ans = 0;

	for (long long i = 0; i < divisors.size(); i++) {
		if (p % divisors[i] != 0) {
			continue;
		}
		long long next = p / divisors[i];

		ans = max(ans, go(next));
	}

	ans += cnt;

	f[p] = ans;
	return f[p];
}

bool validate(vector<long long> &ans) {
	long long cur = 1;
	set<long long> st;
	for (int i = 0; i < ans.size(); i++) {
		cur *= ans[i];
		cur %= m;
		if (isForbid[cur]) {
			return false;
		}
		if (st.find(cur) != st.end()) {
			return false;
		}
		st.insert(cur);
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");

	memset(f, -1, sizeof(f));
	cin >> n >> m;
	for (long long i = 0; i < n; i++) {
		long long q;
		cin >> q;
		forbid.push_back(q);
		isForbid[q] = true;
	}

	long long temp = m;
	for (long long i = 2; i * i <= temp; i++) {
		if (temp % i == 0) {
			divisors.push_back(i);
			while (temp % i == 0) {
				temp /= i;
			}
		}
	}
	if (temp > 1) {
		divisors.push_back(temp);
	}

	long long ans = go(m);

	vector<long long> nums;

	long long cur = m;
	long long lastMult = 1;
	long long globalInverse = 1;
	long long curMul = 1;
	long long lastPhi = 1;
	while (cur > 1) {
		long long curAdded = 0;
		long long phi = 0;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				phi++;
			}
		}

		bool firstAdd = true;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				if (!isForbid[m / cur * i]) {
					if (firstAdd) {
						nums.push_back(((binpow(curMul, lastPhi - 1, cur * lastMult) * lastMult) % m * i) % m);
						firstAdd = false;
					}
					else {
						nums.push_back((((binpow(curMul, phi - 1, cur) * i)) % m) % m);
					}
					curMul = i;
					curAdded++;
				}
			}
		}
		globalInverse *= binpow(curMul, phi - 1, cur);
		globalInverse %= cur;

		lastPhi = phi;

		for (long long i = 0; i < divisors.size(); i++) {
			if (cur % divisors[i] != 0) {
				continue;
			}
			long long next = cur / divisors[i];
			if (f[cur] == curAdded + f[next]) {
				cur = next;
				lastMult = divisors[i];
				break;
			}
		}
	}

	if (!isForbid[0]) {
		ans++;
		nums.push_back(0);
	}

	cout << validate(nums) << endl;

	cout << ans << endl;
	for (long long i = 0; i < nums.size(); i++) {
		cout << nums[i] << " ";
	}

	//system("pause");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N=2e5+5;
int n,m,vis[N],f[N],pre[N];
vector<int> G[N],ans;

int exgcd(int a,int b,int &x,int &y)
{
    if(!b) {x=1,y=0;return a;}
    int d=exgcd(b,a%b,y,x);
    y-=(a/b)*x; return d;
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1,x;i<=n;++i) scanf("%d",&x),vis[x]=1;
    for(int i=0;i<m;++i)
    {
        if(vis[i]) continue;
        G[__gcd(i,m)].push_back(i);
    }
    if(vis[0]) G[m].push_back(0);
    for(int i=1;i<=m;++i) if(!G[i].empty())
    {
        for(int j=1;j<i;++j) if(i%j==0&&f[j]>0)
            if(f[j]>f[i]) f[i]=f[j],pre[i]=j;
        f[i]+=G[i].size();
    }
    for(int x=m;!G[x].empty();x=pre[x])
        for(int y:G[x]) ans.push_back(y);
    reverse(ans.begin(),ans.end());
    if(vis[0]) ans.pop_back();
    printf("%d\n",ans.size());
    int cur=1;
    for(int i:ans)
    {
        int x,y; int d=exgcd(cur,m,x,y);
        printf("%d ",((x*i/d)%m+m)%m);
        cur=i;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N=2e5+5;
int n,m,vis[N],f[N],pre[N];
vector<int> G[N],ans;

int exgcd(int a,int b,int &x,int &y)
{
    if(!b) {x=1,y=0;return a;}
    int d=exgcd(b,a%b,y,x);
    y-=(a/b)*x; return d;
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1,x;i<=n;++i) scanf("%d",&x),vis[x]=1;
    for(int i=0;i<m;++i)
    {
        if(vis[i]) continue;
        G[__gcd(i,m)].push_back(i);
    }
    if(vis[0]) G[m].push_back(0);
    for(int i=1;i<=m;++i) if(!G[i].empty())
    {
        for(int j=1;j<i;++j) if(i%j==0&&f[j]>0)
            if(f[j]>f[i]) f[i]=f[j],pre[i]=j;
        f[i]+=G[i].size();
    }
    for(int x=m;!G[x].empty();x=pre[x])
        for(int y:G[x]) ans.push_back(y);
    reverse(ans.begin(),ans.end());
    if(vis[0]) ans.pop_back();
    printf("%d\n",ans.size());
    int cur=1;
    for(int i:ans)
    {
        int x,y; int d=exgcd(cur,m,x,y);
        printf("%d ",((1LL*x*i/d)%m+m)%m);
        cur=i;
    }
    return 0;
}


#include <bits/stdc++.h>
#define N 200010
using namespace std;
vector<int> ans,prep;
int n,m;
bool book[N];
void dfs(int pre)
{
	int i;
	if(ans.size()<prep.size())
	{
		ans=prep;
	}
	for(i=0;i<m;i++)
	{
		if(!book[(pre*i)%m])
		{
			prep.push_back(i);
			book[(pre*i)%m]=true;
			dfs((pre*i)%m);
			book[(pre*i)%m]=false;
			prep.erase(prep.end()-1);
		}
	}
	return;
}
int main(){
	int i,x;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		cin>>x;
		book[x]=true;
	}
	for(i=0;i<m;i++)
	{
		if(book[i])
		{
			continue;
		}
		prep.clear();
		prep.push_back(i);
		book[i]=true;
		dfs(i);
		book[i]=false;
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	{
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}


#include<cstdio>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn=200000;
int n,m,f[maxn+10],pre[maxn+10],a[maxn+10],acnt; bool b[maxn+10];
vector<int> g[maxn+10];
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll fpow(ll a,ll b,ll mod){
	ll ans=1; for(;b;b/=2,a=a*a%mod) if(b%2) ans=ans*a%mod; return ans;
}
ll phi(ll x){
	ll ans=x; for(int i=2;i*i<=x;++i) if(x%i==0) for(ans=ans/i*(i-1);x%i==0;x/=i);
	if(x>1) ans=ans/x*(x-1); return ans;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		int x; scanf("%d",&x); b[x?x:m]=1;
	}
	for(int i=1;i<=m;++i) if(!b[i]) g[gcd(i,m)].push_back(i);
	for(int i=1;i<=m;++i){
		f[i]+=g[i].size();
		for(int j=i*2;j<=m;j+=i) if(f[i]>f[j]){
			f[j]=f[i]; pre[j]=i;
		}
	}
	for(int i=m;i;i=pre[i]) for(int j=0;j<g[i].size();++j) a[++acnt]=g[i][j];
	printf("%d\n%d ",f[m],a[acnt]%m);
	for(int i=acnt-1;i;--i){
		int g=gcd(a[i+1],m); printf("%lld ",1ll*fpow(a[i+1]/g,phi(m/g)-1,m/g)*a[i]/g%(m/g));
	}
}


#include <cstdio>
#include <vector>
#include <algorithm>
#define ll long long

using namespace std;

const int MAXM = 10000005;

ll read(){
    ll x = 0; int zf = 1; char ch = ' ';
    while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
    if (ch == '-') zf = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}

ll gcd(ll a, ll b){
    if (b > a) swap(a, b);
    while (b > 0){
        int tmp = a % b;
        a = b, b = tmp;
    }
    return a;
}

ll exgcd(ll a, ll b, ll &x, ll &y){
    if (b == 0){
        x = 1, y = 0;
        return a;
    }
    ll res = exgcd(b, a % b, x, y);
    ll tmp = x; x = y, y = tmp - a / b * x;
    return res;
}

bool vis[MAXM];
vector<int> dots[MAXM], edges[MAXM];
ll f[MAXM]; int pre[MAXM];
vector<ll> ans_stk;

int main(){
    int n = read(), m = read();
    for (; n > 0; --n)
        vis[read()] = 1;
    for (int i = 1; i < m; ++i)
        if (!vis[i])
            dots[gcd(i, m)].push_back(i);
    for (int i = 1; i < m; ++i)
        for (int j = i << 1; j < m; j += i)
            edges[i].push_back(j);
    int begin_dot, sz_edge_i, v, f_v;
    for (int i = 0; i < m; ++i){
        f[i] = max(f[i], (ll)(dots[i].size()));
        if (f[i] > f[begin_dot])
            begin_dot = i;
        sz_edge_i = edges[i].size();
        for (int j = 0; j < sz_edge_i; ++j){
            v = edges[i][j], f_v = f[i] + dots[v].size();
            if (f[v] < f_v)
                f[v] = f_v, pre[v] = i;
        }
    }
    int cur_dot = begin_dot, dots_cur_size;
    while (cur_dot){
        dots_cur_size = dots[cur_dot].size();
        for (int i = 0; i < dots_cur_size; ++i)
            ans_stk.push_back(dots[cur_dot][i]);
        cur_dot = pre[cur_dot];
    }
    reverse(ans_stk.begin(), ans_stk.end());
    printf("%d\n", ans_stk.size() + (!vis[0]));
    int ans_size;
    ll a = ans_stk[0], x, y, res;
    if(!ans_stk.empty()){
        printf("%lld ", a);
        ans_size = ans_stk.size();
        for (int i = 1; i < ans_size; ++i){
            res = exgcd(a, m, x, y);
            x *= ((ans_stk[i] / res) % m);
            x %= m;
            x = (x + m) % m;
            printf("%lld ", x);
            a = (a * x) % m;
        }
    }
    if (!vis[0])
        printf("0");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define print_var(x) cerr << #x << " = " << x << endl
#define print_array(arr, len) {cerr << #arr << " = "; for (int i = 0; i < len; i++) cerr << arr[i] << " "; cerr << endl;}
#define print_iterable(it) {cerr << #it << " = "; for (const auto &e : it) cerr << e << " "; cerr << endl;}
#else
#define eprintf(...) (void)0
#define print_var(x) (void)0
#define print_array(arr, len) (void)0
#define print_iterable(it) (void)0
#endif

typedef long long ll;
const int N = 200500;

int n, m;
bool black[N];
vector<int> divs;
int phi[N];
vector<int> go[N];
vector<int> good[N];
int dp[N], par[N];
int powers[N];

int gcd(int x, int y)
{
    if (x != 0)
        return gcd(y % x, x);
    return y;
}

int mul(int a, int b, int mod)
{
    return (ll)a * b % mod;
}

int sub(int a, int b, int mod)
{
    a -= b;
    if (a < 0)
        a += mod;
    return a;
}

int bin_pow(int a, int b, int mod)
{
    int c = 1;
    while (b > 0)
    {
        if (b % 2 == 1)
            c = mul(c, a, mod);
        a = mul(a, a, mod);
        b /= 2;
    }
    return c;
}

vector<int> get_primes(int d)
{
    vector<int> primes;
    for (int i = 2; i * i <= d; i++)
        if (d % i == 0)
        {
            while (d % i == 0)
                d /= i;
            primes.push_back(i);
        }
    if (d > 1)
        primes.push_back(d);
    return primes;
}

int totient(int d)
{
    auto primes = get_primes(d);
    int res = d;
    for (int p : primes)
        res -= res / p;
    return res;
}

void solve()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
    {
        int x;
        scanf("%d", &x);
        black[x] = true;
    }

    for (int d = 1; d * d <= m; d++)
        if (m % d == 0)
        {
            divs.push_back(d);
            if (d * d != m)
                divs.push_back(m / d);
        }
    sort(divs.begin(), divs.end());

    for (int i = 0; i < (int)divs.size(); i++)
        for (int j = i + 1; j < (int)divs.size(); j++)
            if (divs[j] % divs[i] == 0)
                go[divs[i]].push_back(divs[j]);

    for (int d : divs)
    {
        for (int x = 1; x < m / d; x++)
            if (gcd(x, m / d) == 1 && !black[x * d])
                good[d].push_back(x);
    }

    for (int d : divs)
    {
        dp[d] += (int)good[d].size();
        for (int to : go[d])
            if (dp[to] < dp[d])
            {
                dp[to] = dp[d];
                par[to] = d;
            }
    }

    vector<int> path;
    for (int v = m; ; )
    {
        path.push_back(v);
        if (v == 1)
            break;
        v = par[v];
    }
    reverse(path.begin(), path.end());

    vector<int> ans;
    int cur = 1;

    for (int it = 0; it < (int)path.size(); it++)
    {
        int d = path[it];
        if (m / d == 1)
            continue;
        int tot = totient(m / d);

        int ml = it == 0 ? 1 : d / path[it - 1];
        cur %= m / d;
        for (int z : good[d])
        {
            int w = mul(ml, mul(z, bin_pow(cur, tot - 1, m), m), m);
            ans.push_back(w);
            cur = z;
            ml = 1;
        }
    }

    if (!black[0])
        ans.push_back(0);

    printf("%d\n", (int)ans.size());
    cur = 1;
    for (int x : ans)
    {
        cur = mul(cur, x, m);
        if (black[cur])
        {
            print_iterable(ans);
            throw;
        }
        black[cur] = true;
        printf("%d ", x);
    }
    printf("\n");
}

int main()
{
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    solve();

    eprintf("\n\ntime = %.3lf\n", (double)clock() / CLOCKS_PER_SEC);
}


#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,m,imp[202020],k,bf[202020],dp[202020];
vector<int>v[202020];
int op(int x,int y,int &a,int &b)
{
	if(y==0)
	{
		a=1;
		b=0;
		return x;
	}
	int rt=op(y,x%y,b,a);
	b-=a*(x/y);
	return rt;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		imp[a]=1;
	}
	for(int i=1;i<=m;i++)
	{
		if(!imp[i])
		{
			v[__gcd(i,m)].push_back(i);
		}
	}
	for(int i=1;i<m;i++)
	{
		dp[i]+=v[i].size();
		for(int j=i*2;j<m;j+=i)
		{
			if(dp[i]>dp[j])
			{
				dp[j]=dp[i];
				bf[j]=i;
			}
		}
	}
	int ans=0,xh=0;
	for(int i=0;i<m;i++)
	{
		if(dp[i]>ans)
		{
			ans=dp[i];
			xh=i;
		}
	}
	cout<<ans+(!imp[0])<<endl;
	vector<int>vv;
	while(xh)
	{
		for(int i=0;i<v[xh].size();i++)
		{
			vv.push_back(v[xh][i]);
		}
		xh=bf[xh];
	}
	int now=1;
	for(int i=vv.size()-1;i>=0;i--)
	{
		int x,y,cnt=op(now,m,x,y);
		cout<<((x*vv[i]/cnt)%m+m)%m<<' ';
		now=vv[i];
	}
	if(!imp[0])
	{
		cout<<0;
	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
long long n,m,imp[202020],bf[202020],dp[202020];
vector<long long>v[202020],vv;
long long op(long long x,long long y,long long &a,long long &b)
{
	if(!y)
	{
		a=1;
		b=0;
		return x;
	}
	long long rt=op(y,x%y,b,a);
	b-=a*(x/y);
	return rt;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		imp[a]=1;
	}
	for(int i=1;i<=m;i++)
	{
		if(!imp[i])
		{
			v[__gcd(i,(int)m)].push_back(i);
		}
	}
	for(int i=1;i<m;i++)
	{
		dp[i]+=v[i].size();
		for(int j=i*2;j<m;j+=i)
		{
			if(dp[i]>dp[j])
			{
				dp[j]=dp[i];
				bf[j]=i;
			}
		}
	}
	int xh=max_element(dp,dp+m)-dp;
	cout<<dp[xh]+(!imp[0])<<endl;
	for(;xh;xh=bf[xh])
	{
		for(int i=0;i<v[xh].size();i++)
		{
			vv.push_back(v[xh][i]);
		}
	}
	int now=1;
	for(int i=vv.size()-1;i>=0;i--)
	{
		long long x,y,cnt=op(now,m,x,y);
		cout<<((x*vv[i]/cnt)%m+m)%m<<' ';
		now=vv[i];
	}
	if(!imp[0])
	{
		cout<<0;
	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#define int long long
using namespace std;
int n,m,imp[202020],k,bf[202020],dp[202020];
vector<int>v[202020];
int op(int x,int y,int &a,int &b)
{
	if(y==0)
	{
		a=1;
		b=0;
		return x;
	}
	int rt=op(y,x%y,b,a);
	b-=a*(x/y);
	return rt;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		imp[a]=1;
	}
	for(int i=1;i<=m;i++)
	{
		if(!imp[i])
		{
			v[__gcd(i,m)].push_back(i);
		}
	}
	for(int i=1;i<m;i++)
	{
		dp[i]+=v[i].size();
		for(int j=i*2;j<m;j+=i)
		{
			if(dp[i]>dp[j])
			{
				dp[j]=dp[i];
				bf[j]=i;
			}
		}
	}
	int ans=0,xh=0;
	for(int i=0;i<m;i++)
	{
		if(dp[i]>ans)
		{
			ans=dp[i];
			xh=i;
		}
	}
	cout<<ans+(!imp[0])<<endl;
	vector<int>vv;
	while(xh)
	{
		for(int i=0;i<v[xh].size();i++)
		{
			vv.push_back(v[xh][i]);
		}
		xh=bf[xh];
	}
	int now=1;
	for(int i=vv.size()-1;i>=0;i--)
	{
		int x=0,y=0,cnt=op(now,m,x,y);
		cout<<((x*vv[i]/cnt)%m+m)%m<<' ';
		now=vv[i];
	}
	if(!imp[0])
	{
		cout<<0;
	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,m,imp[202020],k,bf[202020],dp[202020];
vector<int>v[202020];
int op(int x,int y,int &a,int &b)
{
	if(y==0)
	{
		a=1;
		b=0;
		return x;
	}
	int rt=op(y,x%y,b,a);
	b-=a*(x/y);
	return rt;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		imp[a]=1;
	}
	for(int i=1;i<=m;i++)
	{
		if(!imp[i])
		{
			v[__gcd(i,m)].push_back(i);
		}
	}
	for(int i=1;i<m;i++)
	{
		dp[i]+=v[i].size();
		for(int j=i*2;j<m;j+=i)
		{
			if(dp[i]>dp[j])
			{
				dp[j]=dp[i];
				bf[j]=i;
			}
		}
	}
	int ans=0,xh=0;
	for(int i=0;i<=m;i++)
	{
		if(dp[i]>ans)
		{
			ans=dp[i];
			xh=i;
		}
	}
	cout<<ans+(!imp[0])<<endl;
	vector<int>vv;
	while(xh)
	{
		for(int i=0;i<v[xh].size();i++)
		{
			vv.push_back(v[xh][i]);
		}
		xh=bf[xh];
	}
	int now=1;
	for(int i=vv.size()-1;i>=0;i--)
	{
		int x=0,y=0,cnt=op(now,m,x,y);
		cout<<((x*vv[i]/cnt)%m+m)%m<<' ';
		now=vv[i];
	}
	if(!imp[0])
	{
		cout<<0<<endl;
	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,m,imp[202020],bf[202020],dp[202020];
vector<int>v[202020];
int op(int x,int y,int &a,int &b)
{
	if(!y)
	{
		a=1;
		b=0;
		return x;
	}
	int rt=op(y,x%y,b,a);
	b-=a*(x/y);
	return rt;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		imp[a]=1;
	}
	for(int i=1;i<=m;i++)
	{
		if(!imp[i])
		{
			v[__gcd(i,m)].push_back(i);
		}
	}
	for(int i=1;i<m;i++)
	{
		dp[i]+=v[i].size();
		for(int j=i*2;j<m;j+=i)
		{
			if(dp[i]>dp[j])
			{
				dp[j]=dp[i];
				bf[j]=i;
			}
		}
	}
	int xh=max_element(dp,dp+m)-dp;
	cout<<dp[xh]+(!imp[0])<<endl;
	vector<int>vv;
	for(;xh;xh=bf[xh])
	{
		for(int i=0;i<v[xh].size();i++)
		{
			vv.push_back(v[xh][i]);
		}
	}
	int now=1;
	for(int i=vv.size()-1;i>=0;i--)
	{
		int x,y,cnt=op(now,m,x,y);
		cout<<((x*vv[i]/cnt)%m+m)%m<<' ';
		now=vv[i];
	}
	if(!imp[0])
	{
		cout<<0;
	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,m,imp[202020],k,bf[202020],dp[202020];
vector<int>v[202020];
int op(int x,int y,int &a,int &b)
{
	if(y==0)
	{
		a=1;
		b=0;
		return x;
	}
	int rt=op(y,x%y,b,a);
	b-=a*(x/y);
	return rt;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		imp[a]=1;
	}
	for(int i=1;i<=m;i++)
	{
		if(!imp[i])
		{
			v[__gcd(i,m)].push_back(i);
		}
	}
	for(int i=1;i<m;i++)
	{
		dp[i]+=v[i].size();
		for(int j=i*2;j<m;j+=i)
		{
			if(dp[i]>dp[j])
			{
				dp[j]=dp[i];
				bf[j]=i;
			}
		}
	}
	int ans=0,xh=0;
	for(int i=0;i<m;i++)
	{
		if(dp[i]>ans)
		{
			ans=dp[i];
			xh=i;
		}
	}
	cout<<ans+(!imp[0])<<endl;
	vector<int>vv;
	while(xh)
	{
		for(int i=0;i<v[xh].size();i++)
		{
			vv.push_back(v[xh][i]);
		}
		xh=bf[xh];
	}
	int now=1;
	for(int i=vv.size()-1;i>=0;i--)
	{
		int x=0,y=0,cnt=op(now,m,x,y);
		cout<<((x*vv[i]/cnt)%m+m)%m<<' ';
		now=vv[i];
	}
	if(!imp[0])
	{
		cout<<0<<endl;
	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,m,imp[202020],bf[202020],dp[202020];
vector<int>v[202020];
int op(int x,int y,int &a,int &b)
{
	if(!y)
	{
		a=1;
		b=0;
		return x;
	}
	int rt=op(y,x%y,b,a);
	b-=a*(x/y);
	return rt;
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		imp[a]=1;
	}
	for(int i=1;i<=m;i++)
	{
		if(!imp[i])
		{
			v[__gcd(i,m)].push_back(i);
		}
	}
	for(int i=1;i<m;i++)
	{
		dp[i]+=v[i].size();
		for(int j=i*2;j<m;j+=i)
		{
			if(dp[i]>dp[j])
			{
				dp[j]=dp[i];
				bf[j]=i;
			}
		}
	}
	int xh=max_element(dp,dp+m)-dp;
	cout<<dp[xh]+(!imp[0])<<endl;
	vector<int>vv;
	for(;xh;xh=bf[xh])
	{
		for(int i=0;i<v[xh].size();i++)
		{
			vv.push_back(v[xh][i]);
		}
	}
	int now=1;
	for(int i=vv.size()-1;i>=0;i--)
	{
		int x,y,cnt=op(now,m,x,y);
		cout<<((x*vv[i]/cnt)%m+m)%m<<' ';
		now=vv[i];
	}
	if(!imp[0])
	{
		cout<<0;
	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,m,imp[202020],bf[202020],dp[202020];
vector<int>v[202020];
int op(int x,int y,int &a,int &b)
{
	if(!y)
	{
		a=1;
		b=0;
		return x;
	}
	int rt=op(y,x%y,b,a);
	b-=a*(x/y);
	return rt;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		imp[a]=1;
	}
	for(int i=1;i<=m;i++)
	{
		if(!imp[i])
		{
			v[__gcd(i,m)].push_back(i);
		}
	}
	for(int i=1;i<m;i++)
	{
		dp[i]+=v[i].size();
		for(int j=i*2;j<m;j+=i)
		{
			if(dp[i]>dp[j])
			{
				dp[j]=dp[i];
				bf[j]=i;
			}
		}
	}
	int ans=-1,xh=-1;
	for(int i=1;i<m;i++)
	{
		if(dp[i]>ans)
		{
			ans=dp[i];
			xh=i;
		}
	}
	cout<<ans+(!imp[0])<<endl;
	vector<int>vv;
	for(;xh;xh=bf[xh])
	{
		for(int i=0;i<v[xh].size();i++)
		{
			vv.push_back(v[xh][i]);
		}
	}
	int now=1;
	for(int i=vv.size()-1;i>=0;i--)
	{
		int x,y,cnt=op(now,m,x,y);
		cout<<((x*vv[i]/cnt)%m+m)%m<<' ';
		now=vv[i];
	}
	if(!imp[0])
	{
		cout<<0;
	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,m,imp[202020],bf[202020],dp[202020];
vector<int>v[202020],vv;
int op(int x,int y,int &a,int &b)
{
	if(!y)
	{
		a=1;
		b=0;
		return x;
	}
	int rt=op(y,x%y,b,a);
	b-=a*(x/y);
	return rt;
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		imp[a]=1;
	}
	for(int i=1;i<=m;i++)
	{
		if(!imp[i])
		{
			v[__gcd(i,m)].push_back(i);
		}
	}
	for(int i=1;i<m;i++)
	{
		dp[i]+=v[i].size();
		for(int j=i*2;j<m;j+=i)
		{
			if(dp[i]>dp[j])
			{
				dp[j]=dp[i];
				bf[j]=i;
			}
		}
	}
	int xh=max_element(dp,dp+m)-dp;
	cout<<dp[xh]+(!imp[0])<<endl;
	for(;xh;xh=bf[xh])
	{
		for(int i=0;i<v[xh].size();i++)
		{
			vv.push_back(v[xh][i]);
		}
	}
	int now=1;
	for(int i=vv.size()-1;i>=0;i--)
	{
		int x,y,cnt=op(now,m,x,y);
		cout<<((x*vv[i]/cnt)%m+m)%m<<' ';
		now=vv[i];
	}
	if(!imp[0])
	{
		cout<<0;
	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,m,imp[202020],k,bf[202020],dp[202020];
vector<int>v[202020];
int op(int x,int y,int &a,int &b)
{
	if(y==0)
	{
		a=1;
		b=0;
		return x;
	}
	int rt=op(y,x%y,b,a);
	b-=a*(x/y);
	return rt;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		imp[a]=1;
	}
	for(int i=1;i<=m;i++)
	{
		if(!imp[i])
		{
			v[__gcd(i,m)].push_back(i);
		}
	}
	for(int i=1;i<m;i++)
	{
		dp[i]+=v[i].size();
		for(int j=i*2;j<m;j+=i)
		{
			if(dp[i]>dp[j])
			{
				dp[j]=dp[i];
				bf[j]=i;
			}
		}
	}
	int ans=0,xh=0;
	for(int i=0;i<m;i++)
	{
		if(dp[i]>ans)
		{
			ans=dp[i];
			xh=i;
		}
	}
	cout<<ans+(!imp[0])<<endl;
	vector<int>vv;
	for(;xh;xh=bf[xh])
	{
		for(int i=0;i<v[xh].size();i++)
		{
			vv.push_back(v[xh][i]);
		}
	}
	int now=1;
	for(int i=vv.size()-1;i>=0;i--)
	{
		int x,y,cnt=op(now,m,x,y);
		cout<<((x*vv[i]/cnt)%m+m)%m<<' ';
		now=vv[i];
	}
	if(!imp[0])
	{
		cout<<0;
	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
long long n,m,imp[202020],k,bf[202020],dp[202020];
vector<long long>v[202020];
long long op(long long x,long long y,long long &a,long long &b)
{
	if(y==0)
	{
		a=1;
		b=0;
		return x;
	}
	long long rt=op(y,x%y,b,a);
	b-=a*(x/y);
	return rt;
}
int main()
{
	cin>>n>>m;
	for(long long i=0;i<n;i++)
	{
		long long a;
		cin>>a;
		imp[a]=1;
	}
	for(long long i=1;i<=m;i++)
	{
		if(!imp[i])
		{
			v[__gcd(i,m)].push_back(i);
		}
	}
	for(long long i=1;i<m;i++)
	{
		dp[i]+=v[i].size();
		for(long long j=i*2;j<m;j+=i)
		{
			if(dp[i]>dp[j])
			{
				dp[j]=dp[i];
				bf[j]=i;
			}
		}
	}
	long long ans=0,xh=0;
	for(long long i=0;i<m;i++)
	{
		if(dp[i]>ans)
		{
			ans=dp[i];
			xh=i;
		}
	}
	cout<<ans+(!imp[0])<<endl;
	vector<long long>vv;
	while(xh)
	{
		for(long long i=0;i<v[xh].size();i++)
		{
			vv.push_back(v[xh][i]);
		}
		xh=bf[xh];
	}
	long long now=1;
	for(long long i=vv.size()-1;i>=0;i--)
	{
		long long x=0,y=0,cnt=op(now,m,x,y);
		cout<<((x*vv[i]/cnt)%m+m)%m<<' ';
		now=vv[i];
	}
	if(!imp[0])
	{
		cout<<0;
	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,m,imp[202020],bf[202020],dp[202020];
vector<int>v[202020];
int op(int x,int y,int &a,int &b)
{
	if(!y)
	{
		a=1;
		b=0;
		return x;
	}
	int rt=op(y,x%y,b,a);
	b-=a*(x/y);
	return rt;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		imp[a]=1;
	}
	for(int i=1;i<=m;i++)
	{
		if(!imp[i])
		{
			v[__gcd(i,m)].push_back(i);
		}
	}
	for(int i=1;i<m;i++)
	{
		dp[i]+=v[i].size();
		for(int j=i*2;j<m;j+=i)
		{
			if(dp[i]>dp[j])
			{
				dp[j]=dp[i];
				bf[j]=i;
			}
		}
	}
	int ans=-1,xh=-1;
	for(int i=0;i<m;i++)
	{
		if(dp[i]>ans)
		{
			ans=dp[i];
			xh=i;
		}
	}
	cout<<ans+(!imp[0])<<endl;
	vector<int>vv;
	for(;xh;xh=bf[xh])
	{
		for(int i=0;i<v[xh].size();i++)
		{
			vv.push_back(v[xh][i]);
		}
	}
	int now=1;
	for(int i=vv.size()-1;i>=0;i--)
	{
		int x,y,cnt=op(now,m,x,y);
		cout<<((x*vv[i]/cnt)%m+m)%m<<' ';
		now=vv[i];
	}
	if(!imp[0])
	{
		cout<<0;
	}
	cout<<endl;
	return 0;
}


#pragma comment (linker, "/STACK:128000000")
#include <iostream>
#include <cstdio>
#include <fstream>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <bitset>
#include <ctime>
#include <sstream>
#include <stack>
#include <cassert>
#include <list>
#include <deque>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

typedef long long li;
typedef long long i64;
typedef pair <int, int> pi;
typedef vector <int> vi;
typedef double ld;
typedef vector<int> vi;
typedef pair <int, int> pi;

void solve();

//int timer = 0;
#define FILENAME ""

int main() {
    string s = FILENAME;
#ifdef YA
    //assert(!s.empty());
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    //cerr<<FILENAME<<endl;
    //assert (s != "change me please");
    clock_t start = clock();
#else
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //freopen(FILENAME ".in", "r", stdin);
    //freopen(FILENAME ".out", "w", stdout);
    cin.tie(0);
#endif
    cout.sync_with_stdio(0);
    cout.precision(10);
    cout << fixed;
    int t = 1;

    //cin >> t;
    for (int i = 1; i <= t; ++i) {
        //++timer;
        //cout << "Case #" << i << ": ";
        solve();
    }
#ifdef YA
    cerr << "\n\n\n" << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n\n\n";
#endif
    return 0;
}

#define int li

int bpow(int x, int step, int mod) {
    if (step == 0) {
        return 1;
    }
    if (step == 1) {
        return x;
    }
    int tmp = bpow(x, step / 2, mod);
    tmp = (tmp * tmp) % mod;
    if (step & 1) {
        tmp = (tmp * x) % mod;
    }
    return tmp;
}

void solve() {
    int N, m;
    cin >> N >> m;
    vector <int> prohibited(m);
    for (int i = 0; i < N; ++i) {
        int x;
        cin >> x;
        prohibited[x] = 1;
    }

    vector <vector <int> > to_div;

    int rest = m;
    for (int j = 2; j * j <= m; ++j) {
        if (rest % j == 0) {
            vector <int> cur;
            cur.push_back(1);
            while (rest % j == 0) {
                rest /= j;
                cur.push_back(cur.back() * j);
            }
            to_div.push_back(cur);
        }
    }
    if (rest != 1) {
        vector <int> cur = {1, rest};
        to_div.push_back(cur);
    }

    vector <int> allowed;
    for (int i = 1; i < m; ++i) {
        if (!prohibited[i]) {
            allowed.push_back(i);
        }
    }

    vector <vector <int> > groups(m);
    for (int x: allowed) {
        int from_m = 1;
        int from_x = x;

        for (int i = 0; i < to_div.size(); ++i) {
            for (int j = to_div[i].size() - 1; j >= 0; --j) {
                if (from_x % to_div[i][j] == 0) {
                    from_x /= to_div[i][j];
                    from_m *= to_div[i][j];
                    break;
                }
            }
        }

        groups[from_m].push_back(from_x);
    }

    int euler = 1;
    for (int i = 0; i < to_div.size(); ++i) {
        euler *= (to_div[i].back() * to_div[i][to_div[i].size() - 2]);
    }

    vector <int> dp(m);
    vector <int> from(m, -1);

    vector <int> divisors(m);
    for (int i = 1; i < m; ++i) {
        if (m % i == 0) {
            divisors[i] = 1;
        }
    }

    for (int i = 1; i < m; ++i) {
        if (!divisors[i]) {
            continue;
        }

        if (dp[i] < groups.size()) {
            dp[i] = groups.size();
        }

        for (int j = 0; j < to_div.size(); ++j) {
            int go = i * to_div[j][1];
            if (go >= m || !divisors[go]) {
                continue;
            }
            int to_upd = dp[i] + groups[go].size();
            if (dp[go] < to_upd) {
                dp[go] = to_upd;
                from[go] = i;
            }
        }
    }

    vector <int> groupspath;

    int best_val = 0;
    int best_start = -1;

    for (int i = 0; i < m; ++i) {
        if (dp[i] > best_val && groups[i].size()) {
            best_val = dp[i];
            best_start = i;
        }
    }

    vector <pair <int, int> > ans;

    while (best_start != -1) {
        for (int x: groups[best_start]) {
            ans.push_back(mp(best_start, x));
        }
        best_start = from[best_start];
    }
    reverse(all(ans));

    vector <int> result;

    for (int i = 0; i < ans.size(); ++i) {
        if (i == 0) {
            result.pb(ans[i].first * ans[i].second);
        } else {
            int first_part = ans[i].first / ans[i - 1].first;
            int second_part = (ans[i].second * bpow(ans[i - 1].second, euler - 1, m)) % m;
            result.pb((first_part * second_part) % m);
        }
    }

    if (!prohibited[0]) {
        result.push_back(0);
    }
    cout << result.size() << "\n";
    for (int x: result) {
        cout << x << " ";
    }
    //rememver about 0!!!
}


#pragma comment (linker, "/STACK:128000000")
#include <iostream>
#include <cstdio>
#include <fstream>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <bitset>
#include <ctime>
#include <sstream>
#include <stack>
#include <cassert>
#include <list>
#include <deque>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

typedef long long li;
typedef long long i64;
typedef pair <int, int> pi;
typedef vector <int> vi;
typedef double ld;
typedef vector<int> vi;
typedef pair <int, int> pi;

void solve();

//int timer = 0;
#define FILENAME ""

int main() {
    string s = FILENAME;
#ifdef YA
    //assert(!s.empty());
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    //cerr<<FILENAME<<endl;
    //assert (s != "change me please");
    clock_t start = clock();
#else
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //freopen(FILENAME ".in", "r", stdin);
    //freopen(FILENAME ".out", "w", stdout);
    cin.tie(0);
#endif
    cout.sync_with_stdio(0);
    cout.precision(10);
    cout << fixed;
    int t = 1;

    //cin >> t;
    for (int i = 1; i <= t; ++i) {
        //++timer;
        //cout << "Case #" << i << ": ";
        solve();
    }
#ifdef YA
    cerr << "\n\n\n" << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n\n\n";
#endif
    return 0;
}

#define int li

int bpow(int x, int step, int mod) {
    if (step == 0) {
        return 1;
    }
    if (step == 1) {
        return x;
    }
    int tmp = bpow(x, step / 2, mod);
    tmp = (tmp * tmp) % mod;
    if (step & 1) {
        tmp = (tmp * x) % mod;
    }
    return tmp;
}

void solve() {
    int N, m;
    cin >> N >> m;
    vector <int> prohibited(m);
    for (int i = 0; i < N; ++i) {
        int x;
        cin >> x;
        prohibited[x] = 1;
    }

    vector <vector <int> > to_div;

    int rest = m;
    for (int j = 2; j * j <= m; ++j) {
        if (rest % j == 0) {
            vector <int> cur;
            cur.push_back(1);
            while (rest % j == 0) {
                rest /= j;
                cur.push_back(cur.back() * j);
            }
            to_div.push_back(cur);
        }
    }
    if (rest != 1) {
        vector <int> cur = {1, rest};
        to_div.push_back(cur);
    }

    vector <int> allowed;
    for (int i = 1; i < m; ++i) {
        if (!prohibited[i]) {
            allowed.push_back(i);
        }
    }

    vector <vector <int> > groups(m);
    for (int x: allowed) {
        int from_m = 1;
        int from_x = x;

        for (int i = 0; i < to_div.size(); ++i) {
            for (int j = to_div[i].size() - 1; j >= 0; --j) {
                if (from_x % to_div[i][j] == 0) {
                    from_x /= to_div[i][j];
                    from_m *= to_div[i][j];
                    break;
                }
            }
        }

        groups[from_m].push_back(from_x);
    }

    int euler = 1;
    for (int i = 0; i < to_div.size(); ++i) {
        euler *= (to_div[i].back() - to_div[i][to_div[i].size() - 2]);
    }

    vector <int> dp(m);
    vector <int> from(m, -1);

    vector <int> divisors(m);
    for (int i = 1; i < m; ++i) {
        if (m % i == 0) {
            divisors[i] = 1;
        }
    }

    for (int i = 1; i < m; ++i) {
        if (!divisors[i]) {
            continue;
        }

        if (dp[i] < groups.size()) {
            dp[i] = groups.size();
        }

        for (int j = 0; j < to_div.size(); ++j) {
            int go = i * to_div[j][1];
            if (go >= m || !divisors[go]) {
                continue;
            }
            int to_upd = dp[i] + groups[go].size();
            if (dp[go] < to_upd) {
                dp[go] = to_upd;
                from[go] = i;
            }
        }
    }

    vector <int> groupspath;

    int best_val = 0;
    int best_start = -1;

    for (int i = 0; i < m; ++i) {
        if (dp[i] > best_val && groups[i].size()) {
            best_val = dp[i];
            best_start = i;
        }
    }

    vector <pair <int, int> > ans;

    while (best_start != -1) {
        for (int x: groups[best_start]) {
            ans.push_back(mp(best_start, x));
        }
        best_start = from[best_start];
    }
    reverse(all(ans));

    vector <int> result;

    for (int i = 0; i < ans.size(); ++i) {
        if (i == 0) {
            result.pb(ans[i].first * ans[i].second);
        } else {
            int first_part = ans[i].first / ans[i - 1].first;
            int second_part = (ans[i].second * bpow(ans[i - 1].second, euler - 1, m)) % m;
            result.pb((first_part * second_part) % m);
        }
    }

    if (!prohibited[0]) {
        result.push_back(0);
    }
    cout << result.size() << "\n";
    for (int x: result) {
        cout << x << " ";
    }
    //rememver about 0!!!
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
using LL = long long;
using ULL = unsigned long long;
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define rep(i, n) for (int (i) = 0; (i) < n; (i)++)
#define until(x) while (!x)
#define fail(s) assert(!s)
const int INF = 0x3f3f3f3f;
const int EPS = 1e-6;
int m, n;
const int N = 200020;
int lim[N];
vector <int> G[N];
#define from first
#define to second
int vis[N], dp[N], path[N];
int exgcd(int a, int b, int &x, int &y) {
	if (!b) {
		x = 1;
		y = 0;
		return a;
	}
	int d = exgcd(b, a % b, y, x);
	y -= x * a / b;
	return d;
}
int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m;
	if (n){
		rep(i, n) {
			int x;
			cin >> x;
			lim[x] = true;
		}
	}
	rep(u, m) {
		if (lim[u])continue;
		G[__gcd(u, m)].pb(u);
	}
	if (lim[0])G[m].pb(0);
	memset(dp, 0, sizeof(dp));
	rep(i, m + 1) {
		if (i == 0)continue;
		if (!G[i].empty()) {
			rep (j, i) {
				if (j == 0)continue;
				if (i % j == 0 && dp[j] > 0) {
					if (dp[j] >= dp[i]) {
						dp[i] = dp[j];
						path[i] = j;
					}
				}
			}
			dp[i] += G[i].size();
		}
	}
	vector <int> ans;
	int x = m;
	while (!G[x].empty()) {
		for (auto y:G[x])ans.pb(y);
		x = path[x];
	}
	if (lim[0])ans.pop_back();
	cout << ans.size() << endl;
	reverse(ans.begin(), ans.end());
	int cur = 1;
	for (auto i:ans) {
		int x, y;
		int d = exgcd(cur, m, x, y);
		cout << ((x * i / d)% m + m) % m << ' ';
		cur = i;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
using LL = long long;
using ULL = unsigned long long;
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define rep(i, n) for (int (i) = 0; (i) < n; (i)++)
#define until(x) while (!x)
#define int long long
#define fail(s) assert(!s)
const int INF = 0x3f3f3f3f;
const int EPS = 1e-6;
int m, n;
const int N = 200020;
int lim[N];
vector <int> G[N];
#define from first
#define to second
int vis[N], dp[N], path[N];
int exgcd(int a,int b, int &x, int &y)
{
    if (!b)
    {
        x = 1;
        y = 0;
        return a;
    }
    int d = exgcd(b, a % b, x, y);
    int z = x; x = y; y = z - y * (a / b);
    return d;
}
signed main()
{
	ios::sync_with_stdio(false);
//	freopen("output.txt", "w", stdout);
	cin >> n >> m;
	if (n){
		rep(i, n) {
			int x;
			cin >> x;
			lim[x] = true;
		}
	}
	rep(u, m) {
		if (lim[u])continue;
		G[__gcd(u, m)].pb(u);
	}
	if (lim[0])G[m].pb(0);
	memset(dp, 0, sizeof(dp));
	rep(i, m + 1) {
		if (i == 0)continue;
		if (!G[i].empty()) {
			dp[i] = 0;
			path[i] = 0;
			rep (j, i) {
				if (j == 0)continue;
				if (i % j == 0 && dp[j] > 0) {
					if (dp[j] > dp[i]) {
						dp[i] = dp[j];
						path[i] = j;
					}
				}
			}
			dp[i] += G[i].size();
		}
	}
	vector <int> ans;
	int x = m;
	while (!G[x].empty()) {
		for (auto y:G[x])ans.pb(y);
		x = path[x];
	}
	if (lim[0])ans.pop_back();
	cout << ans.size() << endl;
	reverse(ans.begin(), ans.end());
	int cur = 1;
	for (auto i:ans) {
		int x, y;
	//	cur = i;
		int d = exgcd(cur, m, x, y);
		cout << ((x * i / d) % m + m) % m << ' ';
		cur = i;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
using LL = long long;
using ULL = unsigned long long;
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define rep(i, n) for (int (i) = 0; (i) < n; (i)++)
#define until(x) while (!x)
#define int long long
#define fail(s) assert(!s)
const int INF = 0x3f3f3f3f;
const int EPS = 1e-6;
int m, n;
const int N = 200020;
int lim[N];
vector <int> G[N];
#define from first
#define to second
int vis[N], dp[N], path[N];
int exgcd(int a,int b, int &x, int &y)
{
    if (!b)
    {
        x = 1;
        y = 0;
        return a;
    }
    int d = exgcd(b, a % b, x, y);
    int z = x; x = y; y = z - y * (a / b);
    return d;
}
signed main()
{
	ios::sync_with_stdio(false);
//	freopen("output.txt", "w", stdout);
	cin >> n >> m;
	if (n){
		rep(i, n) {
			int x;
			cin >> x;
			lim[x] = true;
		}
	}
	rep(u, m) {
		if (lim[u])continue;
		G[__gcd(u, m)].pb(u);
	}
	if (lim[0])G[m].pb(0);
	memset(dp, 0, sizeof(dp));
	rep(i, m + 1) {
		if (i == 0)continue;
		if (!G[i].empty()) {
			dp[i] = 0;
			path[i] = 0;
			rep (j, i) {
				if (j == 0)continue;
				if (i % j == 0 && dp[j] > 0) {
					if (dp[j] > dp[i]) {
						dp[i] = dp[j];
						path[i] = j;
					}
				}
			}
			dp[i] += G[i].size();
		}
	}
	vector <int> ans;
	int x = m;
	while (!G[x].empty()) {
		for (auto y:G[x])ans.pb(y);
		x = path[x];
	}
	reverse(ans.begin(), ans.end());
	if (lim[0])ans.pop_back();
	cout << ans.size() << endl;
	int cur = 1;
	for (auto i:ans) {
		int x, y;
	//	cur = i;
		int d = exgcd(cur, m, x, y);
		cout << ((x * i / d) % m + m) % m << ' ';
		cur = i;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
using LL = long long;
using ULL = unsigned long long;
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define rep(i, n) for (int (i) = 0; (i) < n; (i)++)
#define until(x) while (!x)
#define fail(s) assert(!s)
const int INF = 0x3f3f3f3f;
const int EPS = 1e-6;
int m, n;
const int N = 200020;
int lim[N];
vector <int> G[N];
#define from first
#define to second
int vis[N], dp[N], path[N];
int exgcd(int a,int b, int &x, int &y)
{
    if (!b)
    {
        x = 1;
        y = 0;
        return a;
    }
    int d = exgcd(b, a % b, x, y);
    int z = x; x = y; y = z - y * (a / b);
    return d;
}
int main()
{
	ios::sync_with_stdio(false);
	freopen("output.txt", "w", stdout);
	cin >> n >> m;
	if (n){
		rep(i, n) {
			int x;
			cin >> x;
			lim[x] = true;
		}
	}
	rep(u, m) {
		if (lim[u])continue;
		G[__gcd(u, m)].pb(u);
	}
	if (lim[0])G[m].pb(0);
	memset(dp, 0, sizeof(dp));
	rep(i, m + 1) {
		if (i == 0)continue;
		if (!G[i].empty()) {
			dp[i] = 0;
			path[i] = 0;
			rep (j, i) {
				if (j == 0)continue;
				if (i % j == 0 && dp[j] > 0) {
					if (dp[j] > dp[i]) {
						dp[i] = dp[j];
						path[i] = j;
					}
				}
			}
			dp[i] += G[i].size();
		}
	}
	vector <int> ans;
	int x = m;
	while (!G[x].empty()) {
		for (auto y:G[x])ans.pb(y);
		x = path[x];
	}
	if (lim[0])ans.pop_back();
	cout << ans.size() << endl;
	reverse(ans.begin(), ans.end());
	int cur = 1;
	for (auto i:ans) {
		int x, y;
	//	cur = i;
		int d = exgcd(cur, m, x, y);
		cout << ((x * i / d) % m + m) % m << ' ';
		cur = i;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
using LL = long long;
using ULL = unsigned long long;
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define rep(i, n) for (int (i) = 0; (i) < n; (i)++)
#define until(x) while (!x)
#define int long long
#define fail(s) assert(!s)
const int INF = 0x3f3f3f3f;
const int EPS = 1e-6;
int m, n;
const int N = 200020;
int lim[N];
vector <int> G[N];
#define from first
#define to second
int vis[N], dp[N], path[N];
int exgcd(int a,int b, int &x, int &y)
{
    if (!b)
    {
        x = 1;
        y = 0;
        return a;
    }
    int d = exgcd(b, a % b, x, y);
    int z = x; x = y; y = z - y * (a / b);
    return d;
}
signed main()
{
	ios::sync_with_stdio(false);
//	freopen("output.txt", "w", stdout);
	cin >> n >> m;
	if (n){
		rep(i, n) {
			int x;
			cin >> x;
			lim[x] = true;
		}
	}
	rep(u, m) {
		if (lim[u])continue;
		G[__gcd(u, m)].pb(u);
	}
	if (lim[0])G[m].pb(0);
	memset(dp, 0, sizeof(dp));
	rep(i, m + 1) {
		if (i == 0)continue;
		if (!G[i].empty()) {
			dp[i] = 0;
			path[i] = 0;
			rep (j, i) {
				if (j == 0)continue;
				if (i % j == 0 && dp[j] > 0) {
					if (dp[j] > dp[i]) {
						dp[i] = dp[j];
						path[i] = j;
					}
				}
			}
			dp[i] += G[i].size();
		}
	}
	vector <int> ans;
	int x = m;
	while (!G[x].empty()) {
		for (auto y:G[x])ans.pb(y);
		x = path[x];
	}
	reverse(ans.begin(), ans.end());
	if (lim[0])ans.pop_back();
	cout << ans.size() << endl;
	int cur = 1;
	for (auto i:ans) {
		int x, y;
	//	cur = i;
		int d = exgcd(cur, m, x, y);
		cout << ((x * i / d) % m + m) % m << ' ';
		cur = i;
	}
	return 0;
}

//lg


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
using LL = long long;
using ULL = unsigned long long;
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define rep(i, n) for (int (i) = 0; (i) < n; (i)++)
#define until(x) while (!x)
#define fail(s) assert(!s)
const int INF = 0x3f3f3f3f;
const int EPS = 1e-6;
int m, n;
const int N = 200020;
int lim[N];
vector <int> G[N];
#define from first
#define to second
int vis[N], dp[N], path[N];
int exgcd(int a,int b, int &x, int &y)
{
    if (!b)
    {
        x = 1;
        y = 0;
        return a;
    }
    int d = exgcd(b, a % b, x, y);
    int z = x; x = y; y = z - y * (a / b);
    return d;
}
int main()
{
	ios::sync_with_stdio(false);
//	freopen("output.txt", "w", stdout);
	cin >> n >> m;
	if (n){
		rep(i, n) {
			int x;
			cin >> x;
			lim[x] = true;
		}
	}
	rep(u, m) {
		if (lim[u])continue;
		G[__gcd(u, m)].pb(u);
	}
	if (lim[0])G[m].pb(0);
	memset(dp, 0, sizeof(dp));
	rep(i, m + 1) {
		if (i == 0)continue;
		if (!G[i].empty()) {
			dp[i] = 0;
			path[i] = 0;
			rep (j, i) {
				if (j == 0)continue;
				if (i % j == 0 && dp[j] > 0) {
					if (dp[j] > dp[i]) {
						dp[i] = dp[j];
						path[i] = j;
					}
				}
			}
			dp[i] += G[i].size();
		}
	}
	vector <int> ans;
	int x = m;
	while (!G[x].empty()) {
		for (auto y:G[x])ans.pb(y);
		x = path[x];
	}
	if (lim[0])ans.pop_back();
	cout << ans.size() << endl;
	reverse(ans.begin(), ans.end());
	int cur = 1;
	for (auto i:ans) {
		int x, y;
	//	cur = i;
		int d = exgcd(cur, m, x, y);
		cout << ((x * i / d) % m + m) % m << ' ';
		cur = i;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int Maxn = 200005;
int n, m, maxi, ct, cnt, pos, val[Maxn], head[Maxn], from[Maxn], fac[Maxn], deg[Maxn], f[Maxn];
bool vis[Maxn];
vector <int> Ve[Maxn];
struct edg
{
	int nxt, to;
} edge[20 * Maxn];
void add(int x, int y)
{
	deg[y]++;
	edge[++cnt] = (edg){head[x], y};
	head[x] = cnt;
}
queue <int> Qu;
pair <long long, long long> exgcd(long long x, long long y)
{
	if (!x)
		return make_pair(0, 1);
	else
	{
		pair <long long, long long> tmp = exgcd(y % x, x);
		return make_pair(tmp.second - tmp.first * (y / x), tmp.first);
	}
}
void work(void)
{
	for (int i = 1; i <= m; i++)
		if (!deg[i]) Qu.push(i);
	while (!Qu.empty())
	{
		int u = Qu.front();
		Qu.pop();
		f[u] += Ve[u].size();
		for (int i = head[u]; i; i = edge[i].nxt)
		{
			int to = edge[i].to;
			if (f[to] < f[u])
			{
				f[to] = f[u];
				from[to] = u;
			}
			deg[to]--;
			if (!deg[to]) Qu.push(to);
		}
	}
}
void work(int x, int y)
{
	int l = __gcd(x, m);
	x /= l, y /= l;
	pair <long long, long long> result = exgcd(x, m / l);
	val[++maxi] = y * (result.first % m + m) % m;
}
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
	{
		int x;
		scanf("%d", &x), vis[x] = true;
	}
	for (int i = 0; i < m; i++)
		if (!vis[i]) Ve[__gcd(i, m)].push_back(i);
	for (int i = 1; i <= m; i++)
		if (m % i == 0) fac[++ct] = i;
	for (int i = 1; i <= ct; i++)
		for (int j = i + 1; j <= ct; j++)
			if (fac[j] % fac[i] == 0) add(fac[i], fac[j]);
	work();
	for (int i = 1; i <= m; i++)
		if (maxi < f[i]) maxi = f[i], pos = i;
	int las = -1;
	printf("%d\n", maxi);
	maxi = 0;
	while (pos)
	{
		if (Ve[pos].size())
		{
			if (las == -1) las = *Ve[pos].rbegin(), Ve[pos].pop_back();
			for (vector <int> :: iterator it = Ve[pos].begin(); it != Ve[pos].end(); it++)
				work(*it, las), las = *it;
		}
		pos = from[pos];
	}
	printf("%d ", las);
	for (int i = maxi; i >= 1; i--)
		printf("%d ", val[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int Maxn = 200005;
int n, m, maxi, ct, cnt, pos, val[Maxn], head[Maxn], from[Maxn], fac[Maxn], deg[Maxn], f[Maxn];
bool vis[Maxn];
vector <int> Ve[Maxn];
struct edg
{
	int nxt, to;
} edge[20 * Maxn];
void add(int x, int y)
{
	deg[y]++;
	edge[++cnt] = (edg){head[x], y};
	head[x] = cnt;
}
queue <int> Qu;
pair <int, int> exgcd(int x, int y)
{
	if (!x)
		return make_pair(0, 1);
	else
	{
		pair <int, int> tmp = exgcd(y % x, x);
		return make_pair(tmp.second - tmp.first * (y / x), tmp.first);
	}
}
void work(void)
{
	for (int i = 1; i <= m; i++)
		if (!deg[i]) Qu.push(i);
	while (!Qu.empty())
	{
		int u = Qu.front();
		Qu.pop();
		f[u] += Ve[u].size();
		for (int i = head[u]; i; i = edge[i].nxt)
		{
			int to = edge[i].to;
			if (f[to] < f[u])
			{
				f[to] = f[u];
				from[to] = u;
			}
			deg[to]--;
			if (!deg[to]) Qu.push(to);
		}
	}
}
void work(int x, int y)
{
	pair <int, int> result = exgcd(x, m);
	val[++maxi] = (result.first % m + m) % m;
}
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
	{
		int x;
		scanf("%d", &x), vis[x] = true;
	}
	for (int i = 0; i < m; i++)
		if (!vis[i]) Ve[__gcd(i, m)].push_back(i);
	for (int i = 1; i <= m; i++)
		if (m % i == 0) fac[++ct] = i;
	for (int i = 1; i <= ct; i++)
		for (int j = i + 1; j <= ct; j++)
			if (fac[j] % fac[i] == 0) add(fac[i], fac[j]);
	work();
	for (int i = 1; i <= m; i++)
		if (maxi < f[i]) maxi = f[i], pos = i;
	int las = -1;
	printf("%d\n", maxi);
	maxi = 0;
	while (pos)
	{
		if (Ve[pos].size())
		{
			if (las == -1) las = *Ve[pos].begin();
			for (vector <int> :: iterator it = Ve[pos].begin(); it != Ve[pos].end(); it++)
				work(*it, las), las = *it;
		}
		pos = from[pos];
	}
	for (int i = maxi; i >= 1; i--)
		printf("%d ", val[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int Maxn = 200005;
int n, m, maxi, ct, cnt, pos, val[Maxn], head[Maxn], from[Maxn], fac[Maxn], deg[Maxn], f[Maxn];
bool vis[Maxn];
vector <int> Ve[Maxn];
struct edg
{
	int nxt, to;
} edge[20 * Maxn];
void add(int x, int y)
{
	deg[y]++;
	edge[++cnt] = (edg){head[x], y};
	head[x] = cnt;
}
queue <int> Qu;
pair <int, int> exgcd(int x, int y)
{
	if (!x)
		return make_pair(0, 1);
	else
	{
		pair <int, int> tmp = exgcd(y % x, x);
		return make_pair(tmp.second - tmp.first * (y / x), tmp.first);
	}
}
void work(void)
{
	for (int i = 1; i <= m; i++)
		if (!deg[i]) Qu.push(i);
	while (!Qu.empty())
	{
		int u = Qu.front();
		Qu.pop();
		f[u] += Ve[u].size();
		for (int i = head[u]; i; i = edge[i].nxt)
		{
			int to = edge[i].to;
			if (f[to] < f[u])
			{
				f[to] = f[u];
				from[to] = u;
			}
			deg[to]--;
			if (!deg[to]) Qu.push(to);
		}
	}
}
void work(int x, int y)
{
	int l = __gcd(x, m);
	x /= l, y /= l;
	pair <int, int> result = exgcd(x, m / l);
	val[++maxi] = y * (result.first % m + m) % m;
}
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
	{
		int x;
		scanf("%d", &x), vis[x] = true;
	}
	for (int i = 0; i < m; i++)
		if (!vis[i]) Ve[__gcd(i, m)].push_back(i);
	for (int i = 1; i <= m; i++)
		if (m % i == 0) fac[++ct] = i;
	for (int i = 1; i <= ct; i++)
		for (int j = i + 1; j <= ct; j++)
			if (fac[j] % fac[i] == 0) add(fac[i], fac[j]);
	work();
	for (int i = 1; i <= m; i++)
		if (maxi < f[i]) maxi = f[i], pos = i;
	int las = -1;
	printf("%d\n", maxi);
	maxi = 0;
	while (pos)
	{
		if (Ve[pos].size())
		{
			if (las == -1) las = *Ve[pos].rbegin(), Ve[pos].pop_back();
			for (vector <int> :: iterator it = Ve[pos].begin(); it != Ve[pos].end(); it++)
				work(*it, las), las = *it;
		}
		pos = from[pos];
	}
	printf("%d ", las);
	for (int i = maxi; i >= 1; i--)
		printf("%d ", val[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void exgcd(int a,int b,int&d,int&x,int&y){b?(exgcd(b,a%b,d,y,x),y-=a/b*x):(d=a,x=1,y=0);}
const int N=2e5+3;
bool b[N];
vector<int>v[N];
int d[N],p[N],q[N];
int main(){
	int n,m,i,j,x,t=0;
	scanf("%d%d",&n,&m);
	while(n--)scanf("%d",&j),b[j]=1;
	for(i=0;i<m;++i)if(!b[i])v[gcd(i,m)].push_back(i);
	for(i=1;i<=m;++i){
		d[i]+=v[i].size();
		for(j=i+i;j<=m;j+=i)if(d[j]<d[i])d[j]=d[i],p[j]=i;
	}
	for(i=m;i;i=p[i])for(int j:v[i])q[++t]=j;
	printf("%d\n",t);
	if(t)for(printf("%d ",q[t]);t>1;printf("%d ",((x*1ll*q[--t]/i)%m+m)%m))exgcd(q[t],m,i,x,j);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <chrono>
#include <thread>

using namespace std;

//template<typename T>
//using Matrix2D = std::vector<vector<T>>;

const bool debug = false;

#ifndef M_PI
    const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
//const int mod = int(1e9) + 7;
//const int inf = 1e9;
//double inf = 1e15;
//const long long infLL = 1e11;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 300500; //       e5
//const int SZ = 1010;
//const int delta = 1 << 19;

int a[MX];
int not_allowed[MX];
int dp[MX];
int nxt[MX];
vector<int> c[MX];

int phi(int x){
    int s = x;
    int i = 2;
    while(i * i <= x){
        if(x % i == 0){
            s -= s / i;
            while(x % i == 0) x /= i;
        }
        i++;
    }
    if(x > 1){
        s -= s / x;
    }
    return s;
}

int pow_mod(long long x, int st, int mod){
    long long res = 1;
    x %= mod;
    while(st){
        if(st & 1){
            res = (res * x) % mod;
        }
        st >>= 1;
        x = (x * x) % mod;
    }
    return res % mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    //if(debug)
    //freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    int n, m;
    cin >> n >> m;
    if(m == 1){
        if(n == 0){cout << 1 << endl << 0 << endl;}
        if(n == 1){cout << 0 << endl;}
        return 0;
    }
    int stepin_to_ob = phi(m) - 1;
    //cerr << stepin_to_ob << endl;
    //cerr << pow_mod(3, stepin_to_ob, m) << endl; return 0;
    a[0] = 1;
    int k = 1;
    for(int i = 2; i * i <= m; i++){
        if(m % i == 0){
            a[k++] = i;
            if(i * i == m) break;
            a[k++] = m / i;
        }
    }
    sort(a, a + k);

    for(int i = 0; i < n; i++){
        cin >> not_allowed[i];
    }
    sort(not_allowed, not_allowed + n);
    int pos = 0;
    if(not_allowed[pos] == 0) pos++;

    for(int i = 1; i < m; i++){
        if(i == not_allowed[pos]) {pos++; continue;}
        //cerr << i << ' ';
        int z = 0;
        for(int j = 1; j < k; j++){
            if(i % a[j] == 0) z = j;
        }
        //cerr << z << endl;
        c[z].push_back(i);
    }

    for(int i = k - 1; i >= 0; i--){
        dp[i] = 0;
        nxt[i] = -1;
        for(int j = i + 1; j < k; j++){
            if(a[j] % a[i] == 0){
                if(dp[i] < dp[j]){
                    dp[i] = dp[j];
                    nxt[i] = j;
                }
            }
        }
        dp[i] += c[i].size();
    }
    //cout << dp[0] + 1 << endl;
    int u = 0;
    int s = 1;
    vector<int> ans;
    int prev_k = 1;
    while(u != -1){
        for(int i = 0; i < c[u].size(); i++){
            long long ob = pow(s / prev_k, stepin_to_ob);
            long long nxt = ob * c[u][i] / prev_k;
            nxt %= m;
            s = c[u][i];
            ans.push_back(nxt);
            prev_k = a[u];
        }
        //break;
        u = nxt[u];
    }
    if(n == 0 || not_allowed[0] != 0) ans.push_back(0);
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << ' ';
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <chrono>
#include <thread>

using namespace std;

//template<typename T>
//using Matrix2D = std::vector<vector<T>>;

const bool debug = false;

#ifndef M_PI
    const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
//const int mod = int(1e9) + 7;
//const int inf = 1e9;
//double inf = 1e15;
//const long long infLL = 1e11;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 300500; //       e5
//const int SZ = 1010;
//const int delta = 1 << 19;

int a[MX];
int not_allowed[MX];
int dp[MX];
int nxt[MX];
vector<int> c[MX];

int phi(int x){
    int s = x;
    int i = 2;
    while(i * i <= x){
        if(x % i == 0){
            s -= s / i;
            while(x % i == 0) x /= i;
        }
        i++;
    }
    if(x > 1){
        s -= s / x;
    }
    return s;
}

int pow_mod(long long x, int st, int mod){
    long long res = 1;
    x %= mod;
    while(st){
        if(st & 1){
            res = (res * x) % mod;
        }
        st >>= 1;
        x = (x * x) % mod;
    }
    return res % mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    //if(debug)
    //freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    int n, m;
    cin >> n >> m;
    if(m == 1){
        if(n == 0){cout << 1 << endl << 0 << endl;}
        if(n == 1){cout << 0 << endl;}
        return 0;
    }
    int stepin_to_ob = phi(m) - 1;
    //cerr << stepin_to_ob << endl;
    //cerr << pow_mod(3, stepin_to_ob, m) << endl; return 0;
    a[0] = 1;
    int k = 1;
    for(int i = 2; i * i <= m; i++){
        if(m % i == 0){
            a[k++] = i;
            if(i * i == m) break;
            a[k++] = m / i;
        }
    }
    sort(a, a + k);

    for(int i = 0; i < n; i++){
        cin >> not_allowed[i];
    }
    sort(not_allowed, not_allowed + n);
    int pos = 0;
    if(not_allowed[pos] == 0) pos++;

    for(int i = 1; i < m; i++){
        if(i == not_allowed[pos]) {pos++; continue;}
        //cerr << i << ' ';
        int z = 0;
        for(int j = 1; j < k; j++){
            if(i % a[j] == 0) z = j;
        }
        //cerr << z << endl;
        c[z].push_back(i);
    }

    for(int i = k - 1; i >= 0; i--){
        dp[i] = 0;
        nxt[i] = -1;
        for(int j = i + 1; j < k; j++){
            if(a[j] % a[i] == 0){
                if(dp[i] < dp[j]){
                    dp[i] = dp[j];
                    nxt[i] = j;
                }
            }
        }
        dp[i] += c[i].size();
    }
    //cout << dp[0] + 1 << endl;
    int u = 0;
    int s = 1;
    vector<int> ans;

    while(u != -1){
        for(int i = 0; i < c[u].size(); i++){
            if(i) s /= a[u];
            long long ob = pow(s, stepin_to_ob);
            long long nxt = ob * c[u][i];
            if(i) nxt /= a[u];
            nxt %= m;
            s = c[u][i];
            ans.push_back(nxt);
        }
        //break;
        u = nxt[u];
    }
    if(n == 0 || not_allowed[0] != 0) ans.push_back(0);
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << ' ';
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <chrono>
#include <thread>

using namespace std;

//template<typename T>
//using Matrix2D = std::vector<vector<T>>;

const bool debug = false;

#ifndef M_PI
//    const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
//const int mod = int(1e9) + 7;
//const int inf = 1e9;
//double inf = 1e15;
//const long long infLL = 1e11;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 300500; //       e5
//const int SZ = 1010;
//const int delta = 1 << 19;

int a[MX];
int dp[MX];
int nxt[MX];
vector<int> c[MX];

int phi(int x){
    int s = x;
    int i = 2;
    while(i * i <= x){
        if(x % i == 0){
            s -= s / i;
            while(x % i == 0) x /= i;
        }
        i++;
    }
    if(x > 1){
        s -= s / x;
    }
    return s;
}

int pow_mod(long long x, int st, int mod){
    long long res = 1;
    x %= mod;
    while(st){
        if(st & 1){
            res = (res * x) % mod;
        }
        st >>= 1;
        x = (x * x) % mod;
    }
    return res % mod;
}

int k;

void proc(int x){
    int z = 0;
    for(int j = 1; j < k; j++){
            if((x % a[j]) == 0) z = j;
    }
    c[z].push_back(x);
}

int not_allowed[MX];
int m;

void get_allowed(int n){

    for(int i = 0; i < n; i++){
        cin >> not_allowed[i];
    }
    sort(not_allowed, not_allowed + n);
    int pos = 0;
    if(not_allowed[pos] == 0) pos++;

    for(int i = 1; i < m; i++){
        if(pos < n && i == not_allowed[pos]) {pos++; continue;}
        proc(i);
    }
}

void get_divisors(){
    a[0] = 1;
    k = 1;
    for(int i = 2; i * i <= m; i++){
        if(m % i == 0){
            a[k++] = i;
            if(i * i == m) break;
            a[k++] = m / i;
        }
    }
    sort(a, a + k);
}

int main()
{
    ios_base::sync_with_stdio(false);
    //if(debug)
    //freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    int nn;
    cin >> nn >> m;
    if(m == 1){
        if(nn == 0){cout << 1 << endl << 0 << endl;}
        if(nn == 1){cout << 0 << endl;}
        return 0;
    }
    int stepin_to_ob = phi(m) - 1;
    get_divisors();
    get_allowed(nn);

    for(int i = k - 1; i >= 0; i--){
        dp[i] = 0;
        nxt[i] = -1;
        for(int j = i + 1; j < k; j++){
            if((a[j] % a[i]) == 0){
                if(dp[i] < dp[j]){
                    dp[i] = dp[j];
                    nxt[i] = j;
                }
            }
        }
        dp[i] += c[i].size();
    }
    int u = 0;
    int prev_k = 1;
    vector<int> ans;
    int s = 1;
    while(u != -1){
        for(int i = 0; i < c[u].size(); i++){
            //cerr << "got =" << s << endl;
            long long ob = pow_mod(s / prev_k, stepin_to_ob, m);
            long long nxt = ((ob) % m) * (c[u][i] / prev_k);
            nxt %= m;
            s = c[u][i];
            //cerr << "need " << c[u][i] << " nxt = " << nxt << " ob=" << ob << endl;
            ans.push_back(nxt);
            prev_k = a[u];
        }
        //break;
        u = nxt[u];
    }
    if(nn == 0 || not_allowed[0] != 0) ans.push_back(0);
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << ' ';
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <chrono>
#include <thread>

using namespace std;

//template<typename T>
//using Matrix2D = std::vector<vector<T>>;

const bool debug = false;

#ifndef M_PI
    const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
//const int mod = int(1e9) + 7;
//const int inf = 1e9;
//double inf = 1e15;
//const long long infLL = 1e11;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 300500; //       e5
//const int SZ = 1010;
//const int delta = 1 << 19;

int a[MX];
int not_allowed[MX];
int dp[MX];
int nxt[MX];
vector<int> c[MX];

int phi(int x){
    int s = x;
    int i = 2;
    while(i * i <= x){
        if(x % i == 0){
            s -= s / i;
            while(x % i == 0) x /= i;
        }
        i++;
    }
    if(x > 1){
        s -= s / x;
    }
    return s;
}

int pow_mod(long long x, int st, int mod){
    long long res = 1;
    x %= mod;
    while(st){
        if(st & 1){
            res = (res * x) % mod;
        }
        st >>= 1;
        x = (x * x) % mod;
    }
    return res % mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    //if(debug)
    freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    int n, m;
    cin >> n >> m;
    if(m == 1){
        if(n == 0){cout << 1 << endl << 0 << endl;}
        if(n == 1){cout << 0 << endl;}
        return 0;
    }
    int stepin_to_ob = phi(m) - 1;
    //cerr << stepin_to_ob << endl;
    //cerr << pow_mod(3, stepin_to_ob, m) << endl; return 0;
    a[0] = 1;
    int k = 1;
    for(int i = 2; i * i <= m; i++){
        if(m % i == 0){
            a[k++] = i;
            if(i * i == m) break;
            a[k++] = m / i;
        }
    }
    sort(a, a + k);

    for(int i = 0; i < n; i++){
        cin >> not_allowed[i];
    }
    sort(not_allowed, not_allowed + n);
    int pos = 0;
    if(not_allowed[pos] == 0) pos++;

    for(int i = 1; i < m; i++){
        if(i == not_allowed[pos]) {pos++; continue;}
        //cerr << i << ' ';
        int z = 0;
        for(int j = 1; j < k; j++){
            if(i % a[j] == 0) z = j;
        }
        //cerr << z << endl;
        c[z].push_back(i);
    }

    for(int i = k - 1; i >= 0; i--){
        dp[i] = 0;
        nxt[i] = -1;
        for(int j = i + 1; j < k; j++){
            if(a[j] % a[i] == 0){
                if(dp[i] < dp[j]){
                    dp[i] = dp[j];
                    nxt[i] = j;
                }
            }
        }
        dp[i] += c[i].size();
    }
    //cout << dp[0] + 1 << endl;
    int u = 0;
    int s = 1;
    vector<int> ans;

    while(u != -1){
        for(int i = 0; i < c[u].size(); i++){
            if(i) s /= a[u];
            long long ob = pow(s, stepin_to_ob);
            long long nxt = ob * c[u][i];
            if(i) nxt /= a[u];
            nxt %= m;
            s = c[u][i];
            ans.push_back(nxt);
        }
        //break;
        u = nxt[u];
    }
    if(n == 0 || not_allowed[0] != 0) ans.push_back(0);
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << ' ';
    }
    return 0;
}


using namespace std;
#include<bits/stdc++.h>
#define st first
#define nd second
#define FORE(i,a,b) for(int i=(a),b_=(b);i<=b_;++i)
#define FORD(i,a,b) for(int i=(a),b_=(b);i>=b_;--i)
#define TR(c, it) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)

const int MOD = 1e9 + 7 ;
const int MAXN = 1e5 + 5 ;
int n, m, dp[MAXN], trace[MAXN], F[MAXN] ;
vector <int> divisor[MAXN], g[MAXN] ;
void sieve ()
{
    for(int i = 1 ; i <= m ; ++i )
        for(int j = 2 * i ; j <= m ; j += i) divisor[j].push_back(i) ;
}
long long phi(long long n)
{
    long long result = n;
    for (long long i = 2 ; i * i <= n ; ++i)
        if (n % i == 0)
        {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    if (n > 1)
        result -= result / n;
    return result;
}
long long power (long long a , long long n , long long mod)
{
    long long res = 1 ;
    while(n)
    {
        if(n & 1) res = (res * a) % mod ;
        a = (a * a) % mod ;
        n >>= 1 ;
    }
    return res ;
}
long long Inverse (long long x , long long mod )
{
    return power(x , phi(mod) - 1 , mod) ;
}
long long solve (long long u , long long v , long long mod ) {
   return (v * Inverse(u , mod)) % mod ;
}
int main()
{
#define TASK "NAME"
    // freopen(TASK".inp","r",stdin);
    // freopen(TASK".out","w",stdout);
    scanf("%d %d", &n, &m) ;
    sieve() ;
    for(int i = 0 ; i < n ; ++i )
    {
        int x ;
        scanf("%d",&x) ;
        F[x] = 1 ;
    }
    for(int u = 0 ; u < m ; ++u )
    {
        if (!F[u])
        {
            int v = __gcd(m, u) ;
            g[v].push_back(u) ;
        }
    }

    for(int u = 1 ; u <= m ; ++u )
    {
        dp[u] = g[u].size() ;
        TR(divisor[u], it)
        {
            if (dp[*it] + g[u].size() > dp[u])
            {
                dp[u] = dp[*it] + g[u].size() ;
                trace[u] = *it ;
            }
        }
    }
    vector <int> ans ;
    int u = m ;
    while (u != 0)
    {
        TR(g[u], it) ans.push_back(*it) ;
        u = trace[u] ;
    }
    ans.push_back(1) ;
    reverse(ans.begin() , ans.end() ) ;
   // for(int i = 1 ; i < ans.size() ; ++ i) cout << ans[i] << " "; cout << endl ;
    for(int i = 0 ; i < ans.size() - 1 ; ++i )
    {
        int u = ans[i] , v = ans[i + 1] ;
        cout << solve(u , v , m) << " ";
    }
    return 0;
}


using namespace std;
#include<bits/stdc++.h>
#define st first
#define nd second
#define FORE(i,a,b) for(int i=(a),b_=(b);i<=b_;++i)
#define FORD(i,a,b) for(int i=(a),b_=(b);i>=b_;--i)
#define TR(c, it) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)

const int MOD = 1e9 + 7 ;
const int MAXN = 1e5 + 5 ;
int n, m, dp[MAXN], trace[MAXN], F[MAXN] ;
vector <int> divisor[MAXN], g[MAXN] ;
void sieve ()
{
    for(int i = 1 ; i <= m ; ++i )
        for(int j = 2 * i ; j <= m ; j += i) divisor[j].push_back(i) ;
}
long long phi(long long n)
{
    long long result = n;
    for (long long i = 2 ; i * i <= n ; ++i)
        if (n % i == 0)
        {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    if (n > 1)
        result -= result / n;
    return result;
}
long long power (long long a , long long n , long long mod)
{
    long long res = 1 ;
    while(n)
    {
        if(n & 1) res = (res * a) % mod ;
        a = (a * a) % mod ;
        n >>= 1 ;
    }
    return res ;
}
long long Inverse (long long x , long long mod )
{
    return power(x , phi(mod) - 1 , mod) ;
}
long long solve (long long u , long long v , long long mod ) {
   return (v * Inverse(u , mod)) % mod ;
}
int main()
{
#define TASK "NAME"
    // freopen(TASK".inp","r",stdin);
    // freopen(TASK".out","w",stdout);
    scanf("%d %d", &n, &m) ;
    sieve() ;
    for(int i = 0 ; i < n ; ++i )
    {
        int x ;
        scanf("%d",&x) ;
        F[x] = 1 ;
    }
    for(int u = 0 ; u < m ; ++u )
    {
        if (!F[u])
        {
            int v = __gcd(m, u) ;
            g[v].push_back(u) ;
        }
    }

    for(int u = 1 ; u <= m ; ++u )
    {
        dp[u] = g[u].size() ;
        TR(divisor[u], it)
        {
            if (dp[*it] + g[u].size() > dp[u])
            {
                dp[u] = dp[*it] + g[u].size() ;
                trace[u] = *it ;
            }
        }
    }
    vector <int> ans ;
    int u = m ;
    while (u != 0)
    {
        TR(g[u], it) ans.push_back(*it) ;
        u = trace[u] ;
    }
    ans.push_back(1) ;
    reverse(ans.begin() , ans.end() ) ;
   // for(int i = 1 ; i < ans.size() ; ++ i) cout << ans[i] << " "; cout << endl ;
    cout << ans.size() - 1 << endl ;
    for(int i = 0 ; i < ans.size() - 1 ; ++i )
    {
        int u = ans[i] , v = ans[i + 1] ;
        cout << solve(u , v , m) << " ";
    }
    return 0;
}


using namespace std;
#include<bits/stdc++.h>
#define st first
#define nd second
#define FORE(i,a,b) for(int i=(a),b_=(b);i<=b_;++i)
#define FORD(i,a,b) for(int i=(a),b_=(b);i>=b_;--i)
#define TR(c, it) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)

const int MOD = 1e9 + 7 ;
const int MAXN = 2e5 + 5 ;
int n, m, dp[MAXN], trace[MAXN], F[MAXN] ;
vector <int> divisor[MAXN] , g[MAXN] ;
void sieve ()
{
    for(int i = 1 ; i <= m ; ++i )
        for(int j = 2 * i ; j <= m ; j += i) divisor[j].push_back(i) ;
}
long long phi(long long n)
{
    long long result = n;
    for (long long i = 2 ; i * i <= n ; ++i)
        if (n % i == 0)
        {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    if (n > 1)
        result -= result / n;
    return result;
}
long long power (long long a , long long n , long long mod)
{
    long long res = 1 ;
    while(n)
    {
        if(n & 1) res = (res * a) % mod ;
        a = (a * a) % mod ;
        n >>= 1 ;
    }
    return res ;
}
long long Inverse (long long x , long long mod )
{
    return power(x , phi(mod) - 1 , mod) % mod ;
}
long long moduloInverse(long long a , long long m)
{
    long long q , r , y0 = 0 , y1 = 1 , y , mod = m  ;
    while (a > 0)
    {
        q = m / a ;
        r = m % a ;
        if (!r) return (y % mod + mod) % mod;
        y = y0 - y1 * q ;
        y0 = y1 ;
        y1 =  y;
        m = a;
        a = r ;
    }
}
long long solve (long long u , long long v , long long mod ) {
   long long res = v * Inverse(u , mod) ;
   res %= mod ;
   return res ;
}
int main()
{
#define TASK "801E"
    // freopen(TASK".inp","r",stdin);
    // freopen(TASK".out","w",stdout);
    scanf("%d %d", &n , &m) ;
    sieve() ;
    for(int i = 0 ; i < n ; ++i )
    {
        int x ;
        scanf("%d",&x) ;
        F[x] = 1 ;
    }
    for(int u = 0 ; u < m ; ++u )
    {
        if (!F[u])
        {
            int v = __gcd(m, u) ;
            g[v].push_back(u) ;
        }
    }

    for(int u = 1 ; u <= m ; ++u )
    {
        dp[u] = g[u].size() ;
        TR(divisor[u], it)
        {
            if (dp[*it] + g[u].size() > dp[u])
            {
                dp[u] = dp[*it] + g[u].size() ;
                trace[u] = *it ;
            }
        }
    }
    vector <int> ans ;
    int u = m ;
    while (u != 0)
    {
        TR(g[u], it) ans.push_back(*it) ;
        u = trace[u] ;
    }
    ans.push_back(1) ;
    reverse(ans.begin() , ans.end() ) ;
    //for(int i = 0 ; i < ans.size() ; ++ i) cout << ans[i] << " "; cout << endl ;
    cout << ans.size() - 1 << endl ;
    for(int i = 0 ; i < ans.size() - 1 ; ++i )
    {
        long long u = ans[i] , v = ans[i + 1] ;
        long long d = __gcd(u , (long long)m ) ;
        cout << solve(u / d , v / d , m / d) << " ";
    }
    return 0;
}


using namespace std;
#include<bits/stdc++.h>
#define st first
#define nd second
#define FORE(i,a,b) for(int i=(a),b_=(b);i<=b_;++i)
#define FORD(i,a,b) for(int i=(a),b_=(b);i>=b_;--i)
#define TR(c, it) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)

const int MOD = 1e9 + 7 ;
const int MAXN = 2e5 + 5 ;
int n, m, dp[MAXN], trace[MAXN], F[MAXN] ;
vector <int> divisor[MAXN] , g[MAXN] ;
void sieve ()
{
    for(int i = 1 ; i <= m ; ++i )
        for(int j = 2 * i ; j <= m ; j += i) divisor[j].push_back(i) ;
}
long long phi(long long n)
{
    long long result = n;
    for (long long i = 2 ; i * i <= n ; ++i)
        if (n % i == 0)
        {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    if (n > 1)
        result -= result / n;
    return result;
}
long long power (long long a , long long n , long long mod)
{
    long long res = 1 ;
    while(n)
    {
        if(n & 1) res = (res * a) % mod ;
        a = (a * a) % mod ;
        n >>= 1 ;
    }
    return res ;
}
long long Inverse (long long x , long long mod )
{
    return power(x , phi(mod) - 1 , mod) % mod ;
}
long long moduloInverse(long long a , long long m)
{
    long long q , r , y0 = 0 , y1 = 1 , y , mod = m  ;
    while (a > 0)
    {
        q = m / a ;
        r = m % a ;
        if (!r) return (y % mod + mod) % mod;
        y = y0 - y1 * q ;
        y0 = y1 ;
        y1 =  y;
        m = a;
        a = r ;
    }
}
long long solve (long long u , long long v , long long mod ) {
   long long res = v * Inverse(u , mod) ;
   res %= mod ;
   return res ;
}
int main()
{
#define TASK "801E"
     freopen(TASK".inp","r",stdin);
     freopen(TASK".out","w",stdout);
    scanf("%d %d", &n , &m) ;
    sieve() ;
    for(int i = 0 ; i < n ; ++i )
    {
        int x ;
        scanf("%d",&x) ;
        F[x] = 1 ;
    }
    for(int u = 0 ; u < m ; ++u )
    {
        if (!F[u])
        {
            int v = __gcd(m, u) ;
            g[v].push_back(u) ;
        }
    }

    for(int u = 1 ; u <= m ; ++u )
    {
        dp[u] = g[u].size() ;
        TR(divisor[u], it)
        {
            if (dp[*it] + g[u].size() > dp[u])
            {
                dp[u] = dp[*it] + g[u].size() ;
                trace[u] = *it ;
            }
        }
    }
    vector <int> ans ;
    int u = m ;
    while (u != 0)
    {
        TR(g[u], it) ans.push_back(*it) ;
        u = trace[u] ;
    }
    ans.push_back(1) ;
    reverse(ans.begin() , ans.end() ) ;
    //for(int i = 0 ; i < ans.size() ; ++ i) cout << ans[i] << " "; cout << endl ;
    cout << ans.size() - 1 << endl ;
    for(int i = 0 ; i < ans.size() - 1 ; ++i )
    {
        long long u = ans[i] , v = ans[i + 1] ;
        long long d = __gcd(u , (long long)m ) ;
        cout << solve(u / d , v / d , m / d) << " ";
    }
    return 0;
}


using namespace std;
#include<bits/stdc++.h>
#define st first
#define nd second
#define FORE(i,a,b) for(int i=(a),b_=(b);i<=b_;++i)
#define FORD(i,a,b) for(int i=(a),b_=(b);i>=b_;--i)
#define TR(c, it) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)

const int MOD = 1e9 + 7 ;
const int MAXN = 2e5 + 5 ;
int n, m, dp[MAXN], trace[MAXN], F[MAXN] ;
vector <int> divisor[MAXN] , g[MAXN] ;
void sieve ()
{
    for(int i = 1 ; i <= m ; ++i )
        for(int j = 2 * i ; j <= m ; j += i) divisor[j].push_back(i) ;
}
long long phi(long long n)
{
    long long result = n;
    for (long long i = 2 ; i * i <= n ; ++i)
        if (n % i == 0)
        {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    if (n > 1)
        result -= result / n;
    return result;
}
long long power (long long a , long long n , long long mod)
{
    long long res = 1 ;
    while(n)
    {
        if(n & 1) res = (res * a) % mod ;
        a = (a * a) % mod ;
        n >>= 1 ;
    }
    return res ;
}
long long Inverse (long long x , long long mod )
{
    return power(x , phi(mod) - 1 , mod) % mod ;
}
long long solve (long long u , long long v , long long mod ) {
   return (v * Inverse(u , mod) ) % mod ;
}
int main()
{
#define TASK "NAME"
    // freopen(TASK".inp","r",stdin);
    // freopen(TASK".out","w",stdout);
    scanf("%d %d", &n, &m) ;
    sieve() ;
    for(int i = 0 ; i < n ; ++i )
    {
        int x ;
        scanf("%d",&x) ;
        F[x] = 1 ;
    }
    for(int u = 0 ; u < m ; ++u )
    {
        if (!F[u])
        {
            int v = __gcd(m, u) ;
            g[v].push_back(u) ;
        }
    }

    for(int u = 1 ; u <= m ; ++u )
    {
        dp[u] = g[u].size() ;
        TR(divisor[u], it)
        {
            if (dp[*it] + g[u].size() > dp[u])
            {
                dp[u] = dp[*it] + g[u].size() ;
                trace[u] = *it ;
            }
        }
    }
    vector <int> ans ;
    int u = m ;
    while (u != 0)
    {
        TR(g[u], it) ans.push_back(*it) ;
        u = trace[u] ;
    }
    ans.push_back(1) ;
    reverse(ans.begin() , ans.end() ) ;
   // for(int i = 0 ; i < ans.size() ; ++ i) cout << ans[i] << " "; cout << endl ;
    cout << ans.size() - 1 << endl ;
    for(int i = 0 ; i < ans.size() - 1 ; ++i )
    {
        long long u = ans[i] , v = ans[i + 1] ;
        cout << solve(u , v , m) << " ";
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;
int n,m;
int x,fl[233333];
vector<int> fact,fafa,ans;
int ext_euc(int a, int b, int &x, int &y)
{
	if(b == 0) // gcd(a, b) == a
	{
		x = 1;
		y = 0;
		return a;
	}
	int w = ext_euc(b, a%b, x, y);
	int tmp = x;
	x = y;
	y = tmp - int(a/b)*y;
	return w;
}
int vis[233333],cnt[233333],deg[233333],dp[233333],last[233333];
queue<int> q;
struct edge
{
	int v;
	edge *next;
}*h[233333],pool[233333];
int top;
inline void addedge(int u,int v)
{
	edge *tmp=&pool[top++];tmp->v=v;tmp->next=h[u];h[u]=tmp;deg[v]++;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; i++)
	{
		scanf("%d",&x);
		fl[x]=1;
	}
	int s=sqrt(m);
	for(int i=1; i<=s; i++)
	{
		if(m%i==0)
		{
			fact.push_back(i);
			if(m/i!=i)fact.push_back(m/i);
		}
	}
	sort(fact.begin(),fact.end());
	for(int t=0;t<fact.size();t++)
	{
		for(int tt=0;tt<t;tt++)
			if(fact[t]%fact[tt]==0)
				addedge(fact[t],fact[tt]);
	}
	for(int i=0;i<m;i++)if(!fl[i])cnt[__gcd(i,m)]++;

//	for(int i=1;i<=m;i++)cout<<i<<' '<<cnt[i]<<endl;
	memset(dp,-1,sizeof(dp));
	dp[m]=0;
	q.push(m);
	while(!q.empty())
	{
		int u=q.front();q.pop();
		dp[u]+=cnt[u];
		for(edge *tmp=h[u];tmp;tmp=tmp->next)
		{
//			cout<<u<<"->"<<tmp->v<<endl;
			if(dp[tmp->v]<=dp[u])
			{
				last[tmp->v]=u;
				dp[tmp->v]=dp[u];
			}
			deg[tmp->v]--;
			if(deg[tmp->v]==0)q.push(tmp->v);
		}
	}
	int cur=1;
	fafa.push_back(cur);
	while(cur!=m)
	{
//		cout<<cur<<' '<<last[cur]<<' '<<dp[cur]<<endl;
		cur=last[cur];
		fafa.push_back(cur);
	}
	cur=1;
	for(int t=0; t<fafa.size(); t++)
	{
		for(int i=0; i<m; i++)
		{
			if(fl[i]||__gcd(i,m)!=fafa[t])continue;
//			cout<<"proceed "<<i<<endl;
			int tmp,qwq;
			int d=ext_euc(cur,m,tmp,qwq);
			if(tmp<0)tmp+=m;
//			cout<<"ext_euc "<<cur<<' '<<m<<' '<<tmp<<' '<<qwq<<' '<<d<<endl;
			if(i%d==0)
			{
				ans.push_back((1ll*tmp*(i/d))%m);
				cur=i;
			}
		}
	}
	printf("%d\n",ans.size());
	for(int i=0; i<ans.size(); i++)printf("%d ",ans[i]);
	printf("\n");
//	int tmp=1;for(int i=0;i<ans.size();i++)tmp=tmp*ans[i]%m,cout<<tmp<<' ';
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define div fuckboi
#define nxt suckboi

int a[200010];
int cnt[200010];
vector <int> div;
vector <int> g[2111];
vector <int> v[200010];

int nxt[2111];
int mem[2111];
int n, m;

int dp(int x) {
	if(mem[x] != -1) return mem[x];
	int ans = cnt[div[x]];
	nxt[x] = -1;
	for(auto i : g[x]) {
		int val = cnt[div[x]] + dp(i);
		if(val > ans) {
			ans = val;
			nxt[x] = i;
		}
	}
	return mem[x] = ans;
}

int gcd (int a, int b, int & x, int & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	int x1, y1;
	int d = gcd (b%a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}

int solve(int p, int q) {
	int x, y;
	int d = gcd(p, m, x, y);
	long long ans = 1LL * x * (q / d);
	ans %= m;
	if(ans < 0) ans += m;
	return ans;
}

int main(int argc, char const *argv[])
{
	scanf("%d %d", &n, &m);
	for(int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		a[x] = 1;
	}
	for(int i = 0; i < m; i++) {
		if(a[i] == 1) continue;
		cnt[__gcd(i, m)] += 1;
		v[__gcd(i, m)].push_back(i);
	}
	for(int i = 1; i <= m; i++) {
		if(m % i == 0) {
			div.push_back(i);
		}
	}
	for(int i = 0; i < div.size(); i++) {
		for(int j = 0; j < div.size(); j++) {
			if(i == j) continue;
			if(div[i] % div[j] == 0) {
				g[j].push_back(i);
			}
		}
	}
	memset(mem, -1, sizeof mem);
	int ans = dp(0);
	int cur = 0;

	printf("%d\n", ans);

	vector <int> res;
	while(cur != -1) {
		for(auto i : v[div[cur]]) {
			res.push_back(i);
		}
		cur = nxt[cur];
	}
	for(int i = 0; i < ans; i++) {
		if(i) printf(" %d", solve(res[i - 1], res[i]));
		else printf("%d", res[0]);
	}
	printf("\n");
	return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define Maxn 200000
int gcd(int a,int b){
	if(b==0){
		return a;
	}
	return gcd(b,a%b);
}
vector<int> a[Maxn+5];
int f[Maxn+5];
int pre[Maxn+5];
bool cant[Maxn+5];
int mx(int a,int b){
	return a>b?a:b;
}
int now[Maxn+5];
int phi;
int n,m;
int ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1){
			ans=(int)((long long)ans*a%m);
		}
		a=(int)((long long)a*a%m);
		b>>=1;
	}
	return ans;
}
int get(int a,int b){
	int g=gcd(a,b);
	a/=g,b/=g;
	return (int)((long long)b*ksm(a,phi-1)%m);
}
int main(){
	scanf("%d%d",&n,&m);
	phi=m;
	int _n=m;
	for(int i=2;i*i<=_n;i++){
		if(_n%i==0){
			phi/=i;
			phi*=i-1;
			while(_n%i==0){
				_n/=i;
			}
		}
	}
	if(_n>1){
		phi/=_n;
		phi*=_n-1;
	}
	int x;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		cant[x]=1;
	}
	for(int i=0;i<m;i++){
		if(!cant[i]){
			a[gcd(i,m)].push_back(i);
		}
	}
	for(int i=1;i<=m;i++){
		if(m%i){
			continue;
		}
		f[i]+=a[i].size();
		for(int j=i+i;j<=m;j+=i){
			if(m%j){
				continue;
			}
			if(f[j]<f[i]){
				f[j]=f[i];
				pre[j]=i;
			}
		}
	}
	int tmp=m;
	int len=0;
	while(tmp!=0){
		for(int i=0;i<(int)a[tmp].size();i++){
			now[++len]=a[tmp][i];
		}
		tmp=pre[tmp];
	}
	printf("%d\n",len);
	printf("%d ",now[len]);
	for(int i=len;i>1;i--){
		printf("%d ",get(now[i-1],now[i]));
	}
	puts("");
	return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define Maxn 200000
int gcd(int a,int b){
	if(b==0){
		return a;
	}
	return gcd(b,a%b);
}
vector<int> a[Maxn+5];
int f[Maxn+5];
int pre[Maxn+5];
bool cant[Maxn+5];
int mx(int a,int b){
	return a>b?a:b;
}
int now[Maxn+5];
int phi;
int n,m;
int ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1){
			ans=(int)((long long)ans*a%m);
		}
		a=(int)((long long)a*a%m);
		b>>=1;
	}
	return ans;
}
int get(int a,int b){
	int g=gcd(a,b);
	a/=g,b/=g;
	return (int)((long long)b*ksm(a,phi-1)%m);
}
int main(){
	scanf("%d%d",&n,&m);
	phi=m;
	int _n=m;
	for(int i=2;i*i<=_n;i++){
		if(_n%i==0){
			phi/=i;
			phi*=i-1;
			while(_n%i==0){
				_n/=i;
			}
		}
	}
	if(_n>1){
		phi/=_n;
		phi*=_n-1;
	}
	int x;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		cant[x]=1;
	}
	for(int i=0;i<m;i++){
		if(!cant[i]){
			a[gcd(i,m)].push_back(i);
		}
	}
	for(int i=1;i<=m;i++){
		if(m%i){
			continue;
		}
		f[i]+=a[i].size();
		for(int j=i+i;j<=m;j+=i){
			if(m%j){
				continue;
			}
			if(f[j]<=f[i]){
				f[j]=f[i];
				pre[j]=i;
			}
		}
	}
	int tmp=m;
	int len=0;
	while(tmp!=0){
		for(int i=0;i<(int)a[tmp].size();i++){
			now[++len]=a[tmp][i];
		}
		tmp=pre[tmp];
	}
	printf("%d\n",len);
	printf("%d ",now[len]);
	for(int i=len;i>1;i--){
		printf("%d ",get(now[i-1],now[i]));
	}
	puts("");
	return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define Maxn 200000
int gcd(int a,int b){
	if(b==0){
		return a;
	}
	return gcd(b,a%b);
}
vector<int> a[Maxn+5];
int f[Maxn+5];
int pre[Maxn+5];
bool cant[Maxn+5];
int mx(int a,int b){
	return a>b?a:b;
}
int now[Maxn+5];
int phi;
int n,m;
int ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1){
			ans=(int)((long long)ans*a%m);
		}
		a=(int)((long long)a*a%m);
		b>>=1;
	}
	return ans;
}
int get(int a,int b){
	int g=gcd(a,b);
	a/=g,b/=g;
	return (int)((long long)b*ksm(a,phi-1)%m);
}
int main(){
	scanf("%d%d",&n,&m);
	phi=m;
	int _n=m;
	for(int i=2;i*i<=_n;i++){
		if(_n%i==0){
			phi/=i;
			phi*=i-1;
			while(_n%i==0){
				_n/=i;
			}
		}
	}
	if(_n>1){
		phi/=_n;
		phi*=_n-1;
	}
	int x;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		cant[x]=1;
	}
	for(int i=0;i<m;i++){
		if(!cant[i]){
			a[gcd(i,m)].push_back(i);
		}
	}
	for(int i=1;i<=m;i++){
		if(m%i){
			continue;
		}
		f[i]+=a[i].size();
		for(int j=i+i;j<=m;j+=i){
			if(m%j){
				continue;
			}
			if(f[j]<f[i]){
				f[j]=f[i];
				pre[j]=i;
			}
		}
	}
	int tmp=m;
	int len=0;
	while(tmp!=0){
		for(int i=0;i<(int)a[tmp].size();i++){
			now[++len]=a[tmp][i];
		}
		tmp=pre[tmp];
	}
	printf("%d\n",len);
	printf("%d ",now[len]);
	for(int i=len;i>1;i--){
		printf("%d ",get(now[i],now[i-1]));
	}
	puts("");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

//long long modd=1000000007;
// int dirs[4][2]={{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
// int dirs[8][2]={{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};

int gcd(int a, int b)
{
    if(b==0) return a;
    return gcd(b, a%b);
}

map<int, vector<int> > ma;

int phi(int a)
{
    int ans=a;
    for(int i=2; i*i<=a; i++)
    {
        if(a%i==0)
        {
            ans = (ans/i)*(i-1);
            while(a%i == 0)
            {
                a /= i;
            }
        }
    }
    if(a != 1)
    {
        ans = (ans/a)*(a-1);
    }
    return ans;
}

long long my_pow(int a, int b, int modd)
{
    if(b==0) return 1%modd;
    long long tmp = my_pow(a, b/2, modd);
    long long ret=(tmp*tmp)%modd;
    if(b&1)
    {
        ret = (ret*a)%modd;
    }
    return ret;
}

int mod_inv(int a, int modd)
{
    int b = phi(modd)-1;
    //cerr << b << endl;
    return my_pow(a, b, modd);
}

int primitive(int a, int b, int modd)
{
    long long ret = mod_inv(a, modd);
    ret *= 1LL*b;
    ret %= modd;
    return ret;
}

int n, m;

int needed(int a, int b)
{
    int g = gcd(a, m);
    return primitive(a/g, b/g, m/g);
}

int main()
{
    //cerr << mod_inv(1, 5) << endl;

    //freopen("inp.in", "r", stdin);
    //freopen("outp.out", "w", stdout);
    //ios::sync_with_stdio(false);
    scanf("%d %d", &n, &m);
    vector<bool> forbidden(m+5, false);
    for(int i=0; i<n; i++)
    {
        int foo;
        scanf("%d", &foo);
        forbidden[foo]=true;
    }
    for(int i=1; i<m; i++)
    {
        if(forbidden[i]) continue;
        int g = gcd(i, m);
        ma[g].push_back(i);
    }
    vector<int> out_degree(m+5, 0);
    vector< vector<int> > reverse_edges(m+5);
    vector< vector<int> > forward_edges(m+5);
    vector<int> best(m+5, -1);
    vector<int> go_to(m+5, -1);
    for(auto it1=ma.begin(); it1 != ma.end(); it1++)
    {
        for(auto it2=ma.begin(); it2 != ma.end(); it2++)
        {
            int x=it1->first;
            int y=it2->first;
            if(x==y) continue;
            if(x%y==0)
            {
                out_degree[y]++;
                reverse_edges[x].push_back(y);
                forward_edges[y].push_back(x);
            }
        }
    }
    vector<int> weight(m+5, -1);
    for(int i=1; i<m; i++)
    {
        if(ma.count(i)>0)
        {
            weight[i]=ma[i].size();
        }
    }
    queue<int> q;
    for(int i=1; i<m; i++)
    {
        if(weight[i]==-1) continue;
        if(out_degree[i] != 0) continue;
        best[i]=weight[i];
        q.push(i);
    }
    while(!q.empty())
    {
        int now = q.front();
        q.pop();
        pair<int, int> pa = make_pair(0, -1);
        for(int i=0; i<forward_edges[now].size(); i++)
        {
            int neigh = forward_edges[now][i];
            pa=max(pa, make_pair(best[neigh], neigh));
        }
        best[now]=pa.first+weight[now];
        go_to[now]=pa.second;
        for(int coming_from : reverse_edges[now])
        {
            out_degree[coming_from]--;
            if(out_degree[coming_from]==0)
            {
                q.push(coming_from);
            }
        }
    }
    pair<int, int> to_max=make_pair(0, -1);
    for(int i=1; i<m; i++)
    {
        if(best[i]==-1) continue;
        to_max=max(to_max, make_pair(best[i], i));
    }
    vector<int> path;
    int now = to_max.second;
    while(now != -1)
    {
        path.push_back(now);
        now = go_to[now];
    }

    vector<int> ans;
    int last=1;
    for(int node : path)
    {
        //cerr << "node: " << node << endl;
        for(int dest : ma[node])
        {
            //cerr << "dest: " << dest << endl;
            ans.push_back(needed(last, dest));
            last=dest;
        }
    }
    if(!forbidden[0])
    {
        ans.push_back(0);
    }
    printf("%d\n", ans.size());
    for(int i=0; i<ans.size(); i++)
    {
        if(i != 0)
        {
            printf(" ");
        }
        printf("%d", ans[i]);
    }
    printf("\n");

    return 0;
}


#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
const int MAXN = 200020;
const int INF=0x3f3f3f3f;
bool use[200020]={0};
map<int,vector<int> > mp;
vector<int> fmp;
vector<int> con[130];
#define PB(X) push_back(X)
#define MP(X,Y) make_pair(X,Y)
typedef pair<int,int> PII ;
typedef vector<PII> VII ;

#define INF 0x3FFFFFFF
vector<int> G[MAXN];
void add_edge(int u,int v)
{
    G[u].PB(v);
}
void init(int n){
    for(int i=0;i<n;i++)
		G[i].clear();
}
int vis[MAXN];
int dis[MAXN];
int pre[MAXN];
void spfa(int s,int n)
{
    for(int i = 0;i<n;i++)
		dis[i] = (i == s ? 0 : INF);
    memset(vis,0,sizeof(vis));
	pre[s]=s;
    queue<int>q;
    q.push(s);
    while(!q.empty())
	{
        int x = q.front();
        q.pop();
        vis[x] = 0;
        for(int i = 0;i<G[x].size();i++)
		{
            int y = G[x][i];
            int d =-mp[x].size();
            if(dis[y] > dis[x] + d)
			{
                dis[y] = dis[x] + d;
				pre[y]=x;
                if(!vis[y])
				{
                    q.push(y);
                    vis[y] = 1;
                }
            }
        }
    }
}

int gcd(int a,int b)
{
	return (b==0)?a:gcd(b, a%b);
}

void extgcd(int a,int b,int &d,int &x,int &y)//扩展欧几里得
{

	if(!b)
	{
		d=a;x=1;y=0;
	}
	else
	{
		extgcd(b,a%b,d,y,x);
		y-=x*(a/b);
	}
}

bool modsolve(int a,int b,int m,int &x)
{
	int d,x0,y0;
	extgcd(a,m,d,x0,y0);
	if (b%d==0)
	{
		x=x0*b/d;
		return true;
	}
	return false;
}

vector<int> ans;
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		int a;
		scanf("%d",&a);
		use[a]=true;
	}
	mp[0].push_back(0);
	fmp.push_back(0);
	for(int i=1;i<m;i++)
		if(!use[i])
		{
			int g=gcd(i,m);
			mp[g].push_back(i);
			if(mp[g].size()==1)
				fmp.push_back(g);
		}
	/*cout<<mp.size()<<endl;
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
	{
		cout<<it->first<<"   "<<it->second<<endl;
	}*/
	n=fmp.size();
	mp[m].clear();
	fmp.push_back(m);
	init(n+1);
	add_edge(n,0);
	for(int i=1;i<n;i++)
	{
		add_edge(n,i);
		add_edge(i,0);
		for(int j=i+1;j<n;j++)
			if(fmp[j]%fmp[i]==0)
				add_edge(i,j);
	}
	spfa(n,n+1);
	if(use[0])
		cout<<-dis[0]<<endl;
	else
		cout<<1-dis[0]<<endl;
	int now=0;
	while(pre[now]!=now)
	{
		//cout<<now<<"  "<<fmp[now]<<"  "<<mp[fmp[now]].size()<<endl;
		for(int i=0;i<mp[fmp[now]].size();i++)
			ans.push_back(mp[fmp[now]][i]);
		now=pre[now];
	}
	/*for(int i=ans.size()-1;i>=0;i--)
		cout<<ans[i]<<' ';
	cout<<endl;*/
	int pj=1;
	if(use[0])
		ans.erase(ans.begin());
	for(int i=ans.size()-1;i>=0;i--)
	{
		int tmp;
		modsolve(pj,ans[i],m,tmp);
		while(tmp<0)
			tmp+=m;
		pj=(pj*tmp)%m;
		//printf("%d %d\n",tmp,pj);
		if(i)
			printf("%d ",tmp);
		else
			printf("%d\n",tmp);
	}
	return 0;
}