#ifndef __clang__
#pragma GCC optimize "-O3"
#pragma GCC target "tune=native"
#endif
#ifdef ONLINE_JUDGE
#define NDEBUG 1
#endif
#include <stdio.h>
#include <bits/stdc++.h>

#define DESTRUCT2(p, a, b)                      \
  auto a = get<0>(p);                           \
  auto b = get<1>(p);

#define DESTRUCT3(p, a, b, c)                   \
  auto a = get<0>(p);                           \
  auto b = get<1>(p);                           \
  auto c = get<2>(p);

#define DESTRUCT4(p, a, b, c, d)                \
  auto a = get<0>(p);                           \
  auto b = get<1>(p);                           \
  auto c = get<2>(p);                           \
  auto d = get<3>(p);

#define FOR(i, n)     for(lli i = 0; i < (lli)(n); ++i)
#define FORU(i, j, k) for(lli i = (j); i <= (lli)(k); ++i)
#define FORD(i, j, k) for(lli i = (j); i >= (lli)(k); --i)

#define SQ(x) ((x)*(x))

#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back

using namespace std;

template<typename... As>
struct tpl : public std::tuple<As...> {
  using std::tuple<As...>::tuple;

  template<typename T = tuple<As...> >
  typename tuple_element<0, T>::type const&
  x() const { return get<0>(*this); }
  template<typename T = tuple<As...> >
  typename tuple_element<0, T>::type&
  x() { return get<0>(*this); }

  template<typename T = tuple<As...> >
  typename tuple_element<1, T>::type const&
  y() const { return get<1>(*this); }
  template<typename T = tuple<As...> >
  typename tuple_element<1, T>::type&
  y() { return get<1>(*this); }

  template<typename T = tuple<As...> >
  typename tuple_element<2, T>::type const&
  z() const { return get<2>(*this); }
  template<typename T = tuple<As...> >
  typename tuple_element<2, T>::type&
  z() { return get<2>(*this); }

  template<typename T = tuple<As...> >
  typename tuple_element<3, T>::type const&
  w() const { return get<3>(*this); }
  template<typename T = tuple<As...> >
  typename tuple_element<3, T>::type&
  w() { return get<3>(*this); }
};

using lli   = long long int;
using llu   = long long unsigned;

using pii   = tpl<lli, lli>;
using piii  = tpl<lli, lli, lli>;
using piiii = tpl<lli, lli, lli, lli>;
using vi    = vector<lli>;
using vii   = vector<pii>;
using viii  = vector<piii>;
using vvi   = vector<vi>;
using vvii  = vector<vii>;
using vviii = vector<viii>;

template<class T>
using min_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>
using max_queue = priority_queue<T>;

template<size_t... I>
struct my_index_sequence {
  using type = my_index_sequence;
  static constexpr array<size_t, sizeof...(I)> value = { {I...} };
};

namespace my_index_sequence_detail {
  template<typename I, typename J> struct concat;
  template<size_t... I, size_t... J>
  struct concat<my_index_sequence<I...>, my_index_sequence<J...> > :
    my_index_sequence<I..., (sizeof...(I)+J)...> { };
  template<size_t N> struct make_index_sequence :
    concat<typename make_index_sequence<N/2>::type, typename make_index_sequence<N-N/2>::type>::type { };
  template <> struct make_index_sequence<0> : my_index_sequence<>{};
  template <> struct make_index_sequence<1> : my_index_sequence<0>{};
}

template<class... A>
using my_index_sequence_for = typename my_index_sequence_detail::make_index_sequence<sizeof...(A)>::type;

template<class T, size_t... I>
void print_tuple(ostream& s, T const& a, my_index_sequence<I...>){
  using swallow = int[];
  (void)swallow{0, (void(s << (I == 0? "" : ", ") << get<I>(a)), 0)...};
}

template<class T>
ostream& print_collection(ostream& s, T const& a);
template<class... A>
ostream& operator<<(ostream& s, tpl<A...> const& a);
template<class... A>
ostream& operator<<(ostream& s, tuple<A...> const& a);
template<class A, class B>
ostream& operator<<(ostream& s, pair<A, B> const& a);

template<class T, size_t I>
ostream& operator<<(ostream& s, array<T, I> const& a) { return print_collection(s, a); }
template<class T>
ostream& operator<<(ostream& s, vector<T> const& a) { return print_collection(s, a); }
template<class T, class U>
ostream& operator<<(ostream& s, multimap<T, U> const& a) { return print_collection(s, a); }
template<class T>
ostream& operator<<(ostream& s, multiset<T> const& a) { return print_collection(s, a); }
template<class T, class U>
ostream& operator<<(ostream& s, map<T, U> const& a) { return print_collection(s, a); }
template<class T>
ostream& operator<<(ostream& s, set<T> const& a) { return print_collection(s, a); }

template<class T>
ostream& print_collection(ostream& s, T const& a){
  s << '[';
  for(auto it = begin(a); it != end(a); ++it){
    s << *it;
    if(it != prev(end(a))) s << " ";
  }
  return s << ']';
}

template<class... A>
ostream& operator<<(ostream& s, tpl<A...> const& a){
  s << '(';
  print_tuple(s, a, my_index_sequence_for<A...>{});
  return s << ')';
}

template<class... A>
ostream& operator<<(ostream& s, tuple<A...> const& a){
  s << '(';
  print_tuple(s, a, my_index_sequence_for<A...>{});
  return s << ')';
}

template<class A, class B>
ostream& operator<<(ostream& s, pair<A, B> const& a){
  return s << "(" << get<0>(a) << ", " << get<1>(a) << ")";
}

namespace std {
  namespace {
    template <class T>
    inline void hash_combine(size_t& seed, T const& v) {
      seed ^= hash<T>()(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
    template <class Tuple, size_t Index = tuple_size<Tuple>::value - 1>
    struct HashValueImpl {
      static void apply(size_t& seed, Tuple const& tuple) {
        HashValueImpl<Tuple, Index-1>::apply(seed, tuple);
        hash_combine(seed, get<Index>(tuple));
      }
    };
    template <class Tuple>
    struct HashValueImpl<Tuple, 0> {
      static void apply(size_t& seed, Tuple const& tuple) {
        hash_combine(seed, get<0>(tuple));
      }
    };
  }
  template <typename ... TT>
  struct hash<tuple<TT...>> {
    size_t operator()(tuple<TT...> const& tt) const {
      size_t seed = 0;
      HashValueImpl<tuple<TT...> >::apply(seed, tt);
      return seed;
    }
  };
  template <typename ... TT>
  struct hash<tpl<TT...>> {
    size_t operator()(tpl<TT...> const& tt) const {
      size_t seed = 0;
      HashValueImpl<tuple<TT...> >::apply(seed, tt);
      return seed;
    }
  };
}

lli read_positive(){
  char c; lli x=0;
  do { c = getchar(); } while(c<'0' || c>'9');
  while(c>='0'&&c<='9') {
    x=10*x+(c-'0');
    c = getchar();
  }
  return x;
}

//------------------------------------------------------------------------------

// --- BEGIN SNIPPET MODULAR ---

inline lli fexp(lli a, lli b, lli m) {
  lli r = 1;
  while(b){
    if(b&1) r = (r*a)%m;
    a = (a*a)%m;
    b /= 2;
  }
  return r;
}

inline lli invmod(lli a, lli m) {
  return fexp(a, m-2, m);
}

pii egcd(lli a, lli b) {
  if(a%b==0) {
    return mt(0,1);
  }else{
    pii p = egcd(b,a%b);
    int u=p.x(), v=p.y();
    // u*b + v*r = g
    // a = q*b + r
    // r = a-q*b
    // u*a + v*(a-q*b) = g
    // (u+v)*a - (q*v)*b = g
    return mt(v, u-(a/b)*v);
  }
}

// --- END SNIPPET MODULAR ---

int solveInv(lli a, lli b, lli m) {
  // solve x*a = b [m]
  if(b==0) return 0;
  pii p = egcd(a,m);
  lli g=__gcd(m,a);
  //cerr << b << " " << a << " " << m << " " << p << " " << (((b/g)*p.x())%m+m)%m << endl;
  return (((b/g)*p.x())%m+m)%m;
}

const int N=2e5+3;
bool E[N];
int main(){
  ios::sync_with_stdio(0); cin.tie(0);

  int n,m; cin>>n>>m;

  FOR(i,m) E[i]=0;
  FOR(i,n) {
    int x; cin>>x; E[x]=1;
  }

  map<int,vi> M;
  FOR(x,m) if(E[x] == 0) {
    int g=__gcd<int>(m,x);
    if(x==0) g=0;
    M[g].pb(x);
  }
  map<int,vi> G;
  for(auto const& p:M) for(auto const& q:M) if(p.first!=q.first&&q.first!=0&&p.first%q.first==0) {
        G[q.first].pb(p.first);
      }
  map<int,int> SZ;
  function<void(int)> dfs = [&](int i){
    int bc=0;
    for(int j:G[i]) { dfs(j); bc=max(bc,SZ[j]); }
    SZ[i]=bc+M[i].size();
  };
  for(auto const& p:G) if(SZ.count(p.first)==0) {
      dfs(p.first);
    }
  int best=0, bestVal=-1;
  for(auto const& p:SZ) if(p.second>bestVal) { best=p.first; bestVal=p.second; }

  vi collect;
  function<void(int)> dfs2 = [&](int i) {
    int best=-1, bestVal=-1;
    for(int j:G[i]) if(SZ[j]>bestVal) { bestVal=SZ[j]; best=j; }
    if(best!=-1) dfs2(best);
    collect.insert(end(collect), all(M[i]));
  };
  dfs2(best);
  reverse(all(collect));
  lli cur=1;
  cout << collect.size() << endl;
  for(int x:collect) {
    int y=solveInv(cur,x,m);
    (cur*=y)%=m;
    cout << y << ' ';
    // cout << cur << ' ';
    // cout << y << ' ';
  }
  cout << endl;

  return 0;
}


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

int extended_euclidean(int a, int b, int & x, int & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	int x1, y1;
	int d = extended_euclidean (b%a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}
int modinv(int a,int m){
	int x, y;
	int g = extended_euclidean(a, m, x, y);
	assert(g == 1);
	x = (x % m + m) % m;
	return x;
}
int getnxt(int have,int req,int m){
	int g = __gcd(have,m);
	have /= g;
	int mc = m/g;
	req /= g;

	long long int x = modinv(have,mc);
	//cout<<have<<" "<<m<<" "<<x<<endl;
	x = (x*req)%m;
	return x;
}

map< int,vector<int> > m;
map< int,vector<int> > edges;
pair< int, vector<int> > lpath(int x){
	vector<int> path;
	int bv = 0;
	vector<int> bp;
	for(int i=0;i<edges[x].size();i++){
		auto ret = lpath(edges[x][i]);
		if(ret.first > bv){
			bp = ret.second;
			bv = ret.first;
		}
	}
	bv += m[x].size();
	bp.push_back(x);
	return make_pair(bv,bp);
}
int main(){
	cin.tie(NULL);
	int N,M;cin>>N>>M;
	set<int> forb;
	for(int i=0;i<N;i++){
		int x;cin>>x;
		forb.insert(x);
	}

	m[1].push_back(1);
	for(int i=2;i<M;i++){
		if(forb.count(i) != 0) continue;
		m[__gcd(i,M)].push_back(i);
	}

	for(auto it1 = m.begin();it1 != m.end();it1++){
		auto it2 = it1;
		it2++;
		for(;it2 != m.end();it2++) if(it2->first%it1->first == 0) edges[it1->first].push_back(it2->first);
	}
	auto ret = lpath(1);
	reverse(ret.second.begin(),ret.second.end());
	vector<int> ans;
	int curr = 1;
	for(int i=0;i<ret.second.size();i++){
		int x = ret.second[i];
		for(int j=0;j<m[x].size();j++){
			ans.push_back(getnxt(curr,m[x][j],M));
			curr = m[x][j];
		}
	}
	if(forb.count(0) == 0) ans.push_back(0);
	if(forb.count(1) != 0){
		cout<<ans.size()-1<<endl;
		for(int i=1;i<ans.size();i++) cout<<ans[i]<<" ";
		cout<<endl;
	}else{
		cout<<ans.size()<<endl;
		for(int i=0;i<ans.size();i++) cout<<ans[i]<<" ";
		cout<<endl;
	}
}


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

int extended_euclidean(int a, int b, int & x, int & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	int x1, y1;
	int d = extended_euclidean (b%a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}
int modinv(int a,int m){
	int x, y;
	int g = extended_euclidean(a, m, x, y);
	assert(g == 1);
	x = (x % m + m) % m;
	return x;
}
int getnxt(int have,int req,int m){
	int g = __gcd(have,m);
	have /= g;
	int mc = m/g;
	req /= g;

	long long int x = modinv(have,mc);
	//cout<<have<<" "<<m<<" "<<x<<endl;
	x = (x*req)%m;
	return x;
}

map< int,vector<int> > m;
map< int,vector<int> > edges;
pair< int, vector<int> > lpath(int x){
	vector<int> path;
	int bv = 0;
	vector<int> bp;
	for(int i=0;i<edges[x].size();i++){
		auto ret = lpath(edges[x][i]);
		if(ret.first > bv){
			bp = ret.second;
			bv = ret.first;
		}
	}
	bv += m[x].size();
	bp.push_back(x);
	return make_pair(bv,bp);
}
int main(){
	cin.tie(NULL);
	int N,M;cin>>N>>M;
	set<int> forb;
	for(int i=0;i<N;i++){
		int x;cin>>x;
		forb.insert(x);
	}

	if(M == 1){
		if(forb.count(0) == 0) cout<<"1\n0"<<endl;
		else cout<<"0"<<endl;
		return 0;
	}
	m[1].push_back(1);
	for(int i=2;i<M;i++){
		if(forb.count(i) != 0) continue;
		m[__gcd(i,M)].push_back(i);
	}

	for(auto it1 = m.begin();it1 != m.end();it1++){
		auto it2 = it1;
		it2++;
		for(;it2 != m.end();it2++) if(it2->first%it1->first == 0) edges[it1->first].push_back(it2->first);
	}
	auto ret = lpath(1);
	reverse(ret.second.begin(),ret.second.end());
	vector<int> ans;
	int curr = 1;
	for(int i=0;i<ret.second.size();i++){
		int x = ret.second[i];
		for(int j=0;j<m[x].size();j++){
			ans.push_back(getnxt(curr,m[x][j],M));
			curr = m[x][j];
		}
	}
	if(forb.count(0) == 0) ans.push_back(0);
	if(forb.count(1) != 0){
		cout<<ans.size()-1<<endl;
		for(int i=1;i<ans.size();i++) cout<<ans[i]<<" ";
		cout<<endl;
	}else{
		cout<<ans.size()<<endl;
		for(int i=0;i<ans.size();i++) cout<<ans[i]<<" ";
		cout<<endl;
	}
}


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

const int N = 5000000;
const int M = 10000;

int n,m,tot,ans,vis[N],id[N],in[M],num[M];
int head[M],nxt[N],to[N],f[M],itr[M];
vector<int> que[M];

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

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

inline void AddEdge(int u, int v) {
	static int E = 1; in[u]++;
	to[++E] = u; nxt[E] = head[v]; head[v] = E;
}

void solve(int w) {
	f[w] += que[w].size(); ans = max(ans, f[w]);
	for (int i=head[w];i;i=nxt[i]) {
		if (f[w] > f[to[i]]) itr[to[i]] = w, f[to[i]] = f[w];
		if (--in[to[i]] == 0) solve(to[i]);
	}
}

void exgcd(int a, int b, LL &x, LL &y) {
	if (b) {exgcd(b, a%b, y, x); y -= a / b * x;}
	else {x = 1; y = 0;}
}

inline int REV(int a, int z) {
	int tmp = gcd(a, m), b; LL x, y;
	a /= tmp; z /= tmp; b = m / tmp;
	exgcd(a, b, x, y);
	return x * z % m;
}

void print(int w, int v) {
	for (int i=0;i<=que[w].size()-1;i++) {
		int nv = que[w][i], rev = REV(v, nv);
		printf("%d ",(rev+m)%m); v = nv;
	}
	if (itr[w]) print(itr[w], v);
}

int main() {
	//freopen("11input.in","r",stdin);
	n = read(); m = read();
	for (int i=1;i<=n;i++) vis[read()] = 1;
	for (int i=1;i<m;i++) if (!vis[i]) {
		int tmp = gcd(m, i);
		if (!id[tmp]) id[tmp] = ++tot, num[tot] = tmp;
		que[id[tmp]].push_back(i);
	}
	for (int i=1;i<=tot;i++) {
		for (int j=1;j<=tot;j++) {
			if (num[j] > num[i] && num[j] % num[i] == 0) {
				AddEdge(i, j); //cout<<i<<' '<<j<<endl;
			}
		}
	}
	//for (int i=1;i<=tot;i++) printf("%d %d\n",in[i],cnt[i]);
	for (int i=1;i<=tot;i++) if (!in[i]) solve(i);
	printf("%d\n",ans + !vis[0]);
	for (int i=1;i<=tot;i++) if (f[i] == ans) {print(i, 1); break;}
	if (!vis[0]) putchar('0');
	return 0;
}


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

const int N = 5000000;
const int M = 10000;

int n,m,tot,ans,vis[N],id[N],in[M],cnt[M];
int head[M],nxt[N],to[N],f[M],itr[M],num[M];
vector<int> que[M];

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

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

inline void AddEdge(int u, int v) {
	static int E = 1; in[u]++;
	to[++E] = u; nxt[E] = head[v]; head[v] = E;
}

void solve(int w) {
	f[w] += cnt[w]; ans = max(ans, f[w]);
	for (int i=head[w];i;i=nxt[i]) {
		if (f[w] > f[to[i]]) itr[to[i]] = w, f[to[i]] = f[w];
		if (--in[to[i]] == 0) solve(to[i]);
	}
}

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

inline int REV(int a, int z) {
	int tmp = gcd(a, m), b, x, y;
	a /= tmp; z /= tmp; b = m / tmp;
	exgcd(a, b, x, y);
	return x * z;
}

void print(int w, int v) {
	for (int i=0;i<=que[w].size()-1;i++) {
		int nv = que[w][i], rev = REV(v, nv);
		printf("%d ",((rev%m)+m)%m); v = nv;
	}
	if (itr[w]) print(itr[w], v);
}

int main() {
	//freopen("11input.in","r",stdin);
	n = read(); m = read();
	for (int i=1;i<=n;i++) vis[read()] = 1;
	for (int i=1;i<m;i++) if (!vis[i]) {
		int tmp = gcd(m, i);
		if (!id[tmp]) id[tmp] = ++tot, num[tot] = tmp;
		cnt[id[tmp]]++; que[id[tmp]].push_back(i);
	}
	for (int i=1;i<=tot;i++) {
		for (int j=1;j<=tot;j++) {
			if (num[j] > num[i] && num[j] % num[i] == 0) {
				AddEdge(i, j); //cout<<i<<' '<<j<<endl;
			}
		}
	}
	//for (int i=1;i<=tot;i++) printf("%d %d\n",in[i],cnt[i]);
	for (int i=1;i<=tot;i++) if (!in[i]) solve(i);
	printf("%d\n",ans + !vis[0]);
	for (int i=1;i<=tot;i++) if (f[i] == ans) {print(i, 1); break;}
	if (!vis[0]) putchar('0');
	return 0;
}


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

const int N = 5000000;
const int M = 10000;

int n,m,tot,ans,vis[N],id[N],in[M],num[M];
int head[M],nxt[N],to[N],f[M],itr[M];
vector<int> que[M],vout;

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

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

inline void AddEdge(int u, int v) {
	static int E = 1; in[u]++;
	to[++E] = u; nxt[E] = head[v]; head[v] = E;
}

void solve(int w) {
	f[w] = que[w].size() + (itr[w]?f[itr[w]]:0);
	ans = max(ans, f[w]);
	for (int i=head[w];i;i=nxt[i]) {
		if (f[w] > f[itr[to[i]]]) itr[to[i]] = w;
		if (--in[to[i]] == 0) solve(to[i]);
	}
}

void exgcd(int a, int b, LL &x, LL &y) {
	if (b) {exgcd(b, a%b, y, x); y -= a / b * x;}
	else {x = 1; y = 0;}
}

inline int REV(int a, int z) {
	int tmp = gcd(a, m), b; LL x, y;
	a /= tmp; z /= tmp; b = m / tmp;
	exgcd(a, b, x, y);
	return x * z % m;
}

void print(int w, int v) {
	for (int i=0;i<=que[w].size()-1;i++) {
		int nv = que[w][i], rev = REV(v, nv);
		vout.push_back((rev+m)%m); v = nv;
	}
	if (itr[w]) print(itr[w], v);
}

int main() {
	n = read(); m = read();
	for (int i=1;i<=n;i++) vis[read()] = 1;
	for (int i=1;i<m;i++) if (!vis[i]) {
		int tmp = gcd(m, i);
		if (!id[tmp]) id[tmp] = ++tot, num[tot] = tmp;
		que[id[tmp]].push_back(i);
	}
	for (int i=1;i<=tot;i++) {
		for (int j=1;j<=tot;j++) {
			if (num[j] > num[i] && num[j] % num[i] == 0) {
				AddEdge(i, j);
			}
		}
	}
	for (int i=1;i<=tot;i++) if (!in[i]) solve(i);
	for (int i=1;i<=tot;i++) if (f[i] == ans) {print(i, 1); break;}
	if (!vis[0]) vout.push_back(0); cout<<vout.size()<<endl;
	for (int i=0;i<=vout.size()-1;i++) printf("%d ",vout[i]);
	return 0;
}


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

const int N = 5000000;
const int M = 10000;

int n,m,tot,ans,vis[N],id[N],in[M],num[M];
int head[M],nxt[N],to[N],f[M],itr[M];
vector<int> que[M];

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

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

inline void AddEdge(int u, int v) {
	static int E = 1; in[u]++;
	to[++E] = u; nxt[E] = head[v]; head[v] = E;
}

void solve(int w) {
	f[w] = que[w].size() + f[itr[w]];
	ans = max(ans, f[w]);
	for (int i=head[w];i;i=nxt[i]) {
		if (f[w] > f[itr[to[i]]]) itr[to[i]] = w;
		if (--in[to[i]] == 0) solve(to[i]);
	}
}

void exgcd(int a, int b, LL &x, LL &y) {
	if (b) {exgcd(b, a%b, y, x); y -= a / b * x;}
	else {x = 1; y = 0;}
}

inline int REV(int a, int z) {
	int tmp = gcd(a, m), b; LL x, y;
	a /= tmp; z /= tmp; b = m / tmp;
	exgcd(a, b, x, y);
	return x * z % m;
}

void print(int w, int v) {
	for (int i=0;i<=que[w].size()-1;i++) {
		int nv = que[w][i], rev = REV(v, nv);
		printf("%d ",(rev+m)%m); v = nv;
	}
	if (itr[w]) print(itr[w], v);
}

int main() {
	//freopen("11input.in","r",stdin);
	n = read(); m = read();
	for (int i=1;i<=n;i++) vis[read()] = 1;
	for (int i=1;i<m;i++) if (!vis[i]) {
		int tmp = gcd(m, i);
		if (!id[tmp]) id[tmp] = ++tot, num[tot] = tmp;
		que[id[tmp]].push_back(i);
	}
	for (int i=1;i<=tot;i++) {
		for (int j=1;j<=tot;j++) {
			if (num[j] > num[i] && num[j] % num[i] == 0) {
				AddEdge(i, j); //cout<<i<<' '<<j<<endl;
			}
		}
	}
	//for (int i=1;i<=tot;i++) printf("%d %d\n",in[i],cnt[i]);
	for (int i=1;i<=tot;i++) if (!in[i]) solve(i);
	printf("%d\n",ans + !vis[0]);
	for (int i=1;i<=tot;i++) if (f[i] == ans) {print(i, 1); break;}
	if (!vis[0]) printf("0 ");
	return 0;
}


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

const int N = 5000000;
const int M = 10000;

int n,m,tot,ans,vis[N],id[N],in[M],num[M];
int head[M],nxt[N],to[N],f[M],itr[M];
vector<int> que[M],vout;

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

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

inline void AddEdge(int u, int v) {
	static int E = 1; in[u]++;
	to[++E] = u; nxt[E] = head[v]; head[v] = E;
}

void solve(int w) {
	f[w] = que[w].size() + (itr[w]?f[itr[w]]:0);
	ans = max(ans, f[w]);
	for (int i=head[w];i;i=nxt[i]) {
		if (f[w] > f[itr[to[i]]]) itr[to[i]] = w;
		if (--in[to[i]] == 0) solve(to[i]);
	}
}

void exgcd(int a, int b, LL &x, LL &y) {
	if (b) {exgcd(b, a%b, y, x); y -= a / b * x;}
	else {x = 1; y = 0;}
}

inline int REV(int a, int z) {
	int tmp = gcd(a, m), b; LL x, y;
	a /= tmp; z /= tmp; b = m / tmp;
	exgcd(a, b, x, y);
	return x * z % m;
}

void print(int w, int v) {
	for (int i=0;i<=que[w].size()-1;i++) {
		int nv = que[w][i], rev = REV(v, nv);
		vout.push_back((rev+m)%m); v = nv;
	}
	if (itr[w]) print(itr[w], v);
}

int main() {
	//freopen("11input.in","r",stdin);
	n = read(); m = read();
	for (int i=1;i<=n;i++) vis[read()] = 1;
	for (int i=1;i<m;i++) if (!vis[i]) {
		int tmp = gcd(m, i);
		if (!id[tmp]) id[tmp] = ++tot, num[tot] = tmp;
		que[id[tmp]].push_back(i);
	}
	for (int i=1;i<=tot;i++) {
		for (int j=1;j<=tot;j++) {
			if (num[j] > num[i] && num[j] % num[i] == 0) {
				AddEdge(i, j); //cout<<i<<' '<<j<<endl;
			}
		}
	}
	//for (int i=1;i<=tot;i++) printf("%d %d\n",in[i],cnt[i]);
	for (int i=1;i<=tot;i++) if (!in[i]) solve(i);
	for (int i=1;i<=tot;i++) if (f[i] == ans) {print(i, 1); break;}
	if (!vis[0]) vout.push_back(0); cout<<vout.size()<<endl;
	for (int i=0;i<=vout.size()-1;i++) printf("%d ",vout[i]);
	if (ans != vout.size()) cout<<endl<<"FUCK";
	return 0;
}


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

const int N = 5000000;
const int M = 10000;

int n,m,tot,ans,vis[N],id[N],in[M],cnt[M];
int head[M],nxt[N],to[N],f[M],itr[M],num[M];
vector<int> que[M];

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

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

inline void AddEdge(int u, int v) {
	static int E = 1; in[u]++;
	to[++E] = u; nxt[E] = head[v]; head[v] = E;
}

void solve(int w) {
	f[w] += cnt[w]; ans = max(ans, f[w]);
	for (int i=head[w];i;i=nxt[i]) {
		if (f[w] > f[to[i]]) itr[to[i]] = w, f[to[i]] = f[w];
		if (--in[to[i]] == 0) solve(to[i]);
	}
}

void exgcd(int a, int b, LL &x, LL &y) {
	if (b) {exgcd(b, a%b, y, x); y -= a / b * x;}
	else {x = 1; y = 0;}
}

inline int REV(int a, int z) {
	int tmp = gcd(a, m), b; LL x, y;
	a /= tmp; z /= tmp; b = m / tmp;
	exgcd(a, b, x, y);
	return x * z % m;
}

void print(int w, int v) {
	for (int i=0;i<=que[w].size()-1;i++) {
		int nv = que[w][i], rev = REV(v, nv);
		printf("%d ",(rev+m)%m); v = nv;
	}
	if (itr[w]) print(itr[w], v);
}

int main() {
	//freopen("11input.in","r",stdin);
	n = read(); m = read();
	for (int i=1;i<=n;i++) vis[read()] = 1;
	for (int i=1;i<m;i++) if (!vis[i]) {
		int tmp = gcd(m, i);
		if (!id[tmp]) id[tmp] = ++tot, num[tot] = tmp;
		cnt[id[tmp]]++; que[id[tmp]].push_back(i);
	}
	for (int i=1;i<=tot;i++) {
		for (int j=1;j<=tot;j++) {
			if (num[j] > num[i] && num[j] % num[i] == 0) {
				AddEdge(i, j); //cout<<i<<' '<<j<<endl;
			}
		}
	}
	//for (int i=1;i<=tot;i++) printf("%d %d\n",in[i],cnt[i]);
	for (int i=1;i<=tot;i++) if (!in[i]) solve(i);
	printf("%d\n",ans + !vis[0]);
	for (int i=1;i<=tot;i++) if (f[i] == ans) {print(i, 1); break;}
	if (!vis[0]) putchar('0');
	return 0;
}


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

const int N = 5000000;
const int M = 10000;

int n,m,tot,ans,vis[N],id[N],in[M],num[M];
int head[M],nxt[N],to[N],f[M],itr[M];
vector<int> que[M],vout;

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

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

inline void AddEdge(int u, int v) {
	static int E = 1; in[u]++;
	to[++E] = u; nxt[E] = head[v]; head[v] = E;
}

void solve(int w) {
	f[w] = que[w].size() + (itr[w]?f[itr[w]]:0);
	ans = max(ans, f[w]);
	for (int i=head[w];i;i=nxt[i]) {
		if (f[w] > f[itr[to[i]]]) itr[to[i]] = w;
		if (--in[to[i]] == 0) solve(to[i]);
	}
}

void exgcd(int a, int b, LL &x, LL &y) {
	if (b) {exgcd(b, a%b, y, x); y -= a / b * x;}
	else {x = 1; y = 0;}
}

inline int REV(int a, int z) {
	int tmp = gcd(a, m), b; LL x, y;
	a /= tmp; z /= tmp; b = m / tmp;
	exgcd(a, b, x, y);
	return x * z % m;
}

void print(int w, int v) {
	for (int i=0;i<=que[w].size()-1;i++) {
		int nv = que[w][i], rev = REV(v, nv);
		vout.push_back((rev+m)%m); v = nv;
	}
	if (itr[w]) print(itr[w], v);
}

int main() {
	//freopen("11input.in","r",stdin);
	n = read(); m = read();
	for (int i=1;i<=n;i++) vis[read()] = 1;
	for (int i=1;i<m;i++) if (!vis[i]) {
		int tmp = gcd(m, i);
		if (!id[tmp]) id[tmp] = ++tot, num[tot] = tmp;
		que[id[tmp]].push_back(i);
	}
	for (int i=1;i<=tot;i++) {
		for (int j=1;j<=tot;j++) {
			if (num[j] > num[i] && num[j] % num[i] == 0) {
				AddEdge(i, j); //cout<<i<<' '<<j<<endl;
			}
		}
	}
	//for (int i=1;i<=tot;i++) printf("%d %d\n",in[i],cnt[i]);
	for (int i=1;i<=tot;i++) if (!in[i]) solve(i);
	for (int i=1;i<=tot;i++) if (f[i] == ans) {print(i, 1); break;}
	if (!vis[0]) vout.push_back(0), ++ans; cout<<vout.size()<<endl;
	for (int i=0;i<=vout.size()-1;i++) printf("%d ",vout[i]);
	if (ans != vout.size()) cout<<endl<<"FUCK";
	return 0;
}


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

const int N = 5000000;
const int M = N;

int n,m,tot,ans,vis[N],id[N],in[M],num[M];
int head[M],nxt[N],to[N],f[M],itr[M];
vector<int> que[M];

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

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

inline void AddEdge(int u, int v) {
	static int E = 1; in[u]++;
	to[++E] = u; nxt[E] = head[v]; head[v] = E;
}

void solve(int w) {
	f[w] = que[w].size() + f[itr[w]];
	ans = max(ans, f[w]);
	for (int i=head[w];i;i=nxt[i]) {
		if (f[w] > f[itr[to[i]]]) itr[to[i]] = w;
		if (--in[to[i]] == 0) solve(to[i]);
	}
}

void exgcd(int a, int b, LL &x, LL &y) {
	if (b) {exgcd(b, a%b, y, x); y -= a / b * x;}
	else {x = 1; y = 0;}
}

inline int REV(int a, int z) {
	int tmp = gcd(a, m), b; LL x, y;
	a /= tmp; z /= tmp; b = m / tmp;
	exgcd(a, b, x, y);
	return x * z % m;
}

void print(int w, int v) {
	for (int i=0;i<=que[w].size()-1;i++) {
		int nv = que[w][i], rev = REV(v, nv);
		printf("%d ",(rev+m)%m); v = nv;
	}
	if (itr[w]) print(itr[w], v);
}

int main() {
	//freopen("11input.in","r",stdin);
	n = read(); m = read();
	for (int i=1;i<=n;i++) vis[read()] = 1;
	for (int i=1;i<m;i++) if (!vis[i]) {
		int tmp = gcd(m, i);
		if (!id[tmp]) id[tmp] = ++tot, num[tot] = tmp;
		que[id[tmp]].push_back(i);
	}
	for (int i=1;i<=tot;i++) {
		for (int j=1;j<=tot;j++) {
			if (num[j] > num[i] && num[j] % num[i] == 0) {
				AddEdge(i, j); //cout<<i<<' '<<j<<endl;
			}
		}
	}
	//for (int i=1;i<=tot;i++) printf("%d %d\n",in[i],cnt[i]);
	for (int i=1;i<=tot;i++) if (!in[i]) solve(i);
	printf("%d\n",ans + !vis[0]);
	for (int i=1;i<=tot;i++) if (f[i] == ans) {print(i, 1); break;}
	if (!vis[0]) printf("0 ");
	return 0;
}


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

const int N = 5000000;
const int M = 10000;

int n,m,tot,ans,vis[N],id[N],in[M],num[M];
int head[M],nxt[N],to[N],f[M],itr[M];
vector<int> que[M];

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

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

inline void AddEdge(int u, int v) {
	static int E = 1; in[u]++;
	to[++E] = u; nxt[E] = head[v]; head[v] = E;
}

void solve(int w) {
	f[w] = que[w].size() + f[itr[w]];
	ans = max(ans, f[w]);
	for (int i=head[w];i;i=nxt[i]) {
		if (f[w] > f[itr[to[i]]]) itr[to[i]] = w;
		if (--in[to[i]] == 0) solve(to[i]);
	}
}

void exgcd(int a, int b, LL &x, LL &y) {
	if (b) {exgcd(b, a%b, y, x); y -= a / b * x;}
	else {x = 1; y = 0;}
}

inline int REV(int a, int z) {
	int tmp = gcd(a, m), b; LL x, y;
	a /= tmp; z /= tmp; b = m / tmp;
	exgcd(a, b, x, y);
	return x * z % m;
}

void print(int w, int v) {
	for (int i=0;i<=que[w].size()-1;i++) {
		int nv = que[w][i], rev = REV(v, nv);
		printf("%d ",(rev+m)%m); v = nv;
	}
	if (itr[w]) print(itr[w], v);
}

int main() {
	//freopen("11input.in","r",stdin);
	n = read(); m = read();
	for (int i=1;i<=n;i++) vis[read()] = 1;
	for (int i=1;i<m;i++) if (!vis[i]) {
		int tmp = gcd(m, i);
		if (!id[tmp]) id[tmp] = ++tot, num[tot] = tmp;
		que[id[tmp]].push_back(i);
	}
	for (int i=1;i<=tot;i++) {
		for (int j=1;j<=tot;j++) {
			if (num[j] > num[i] && num[j] % num[i] == 0) {
				AddEdge(i, j); //cout<<i<<' '<<j<<endl;
			}
		}
	}
	//for (int i=1;i<=tot;i++) printf("%d %d\n",in[i],cnt[i]);
	for (int i=1;i<=tot;i++) if (!in[i]) solve(i);
	printf("%d\n",ans + !vis[0]);
	for (int i=1;i<=tot;i++) if (f[i] == ans) {print(i, 1); break;}
	if (!vis[0]) putchar('0');
	return 0;
}


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

const int N = 5000000;
const int M = 10000;

int n,m,tot,ans,vis[N],id[N],in[M],num[M];
int head[M],nxt[N],to[N],f[M],itr[M];
vector<int> que[M],vout;

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

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

inline void AddEdge(int u, int v) {
	static int E = 1; in[u]++;
	to[++E] = u; nxt[E] = head[v]; head[v] = E;
}

void solve(int w) {
	f[w] = que[w].size() + f[itr[w]];
	ans = max(ans, f[w]);
	for (int i=head[w];i;i=nxt[i]) {
		if (f[w] > f[itr[to[i]]]) itr[to[i]] = w;
		if (--in[to[i]] == 0) solve(to[i]);
	}
}

void exgcd(int a, int b, LL &x, LL &y) {
	if (b) {exgcd(b, a%b, y, x); y -= a / b * x;}
	else {x = 1; y = 0;}
}

inline int REV(int a, int z) {
	int tmp = gcd(a, m), b; LL x, y;
	a /= tmp; z /= tmp; b = m / tmp;
	exgcd(a, b, x, y);
	return x * z % m;
}

void print(int w, int v) {
	for (int i=0;i<=que[w].size()-1;i++) {
		int nv = que[w][i], rev = REV(v, nv);
		vout.push_back((rev+m)%m); v = nv;
	}
	if (itr[w]) print(itr[w], v);
}

int main() {
	//freopen("11input.in","r",stdin);
	n = read(); m = read();
	for (int i=1;i<=n;i++) vis[read()] = 1;
	for (int i=1;i<m;i++) if (!vis[i]) {
		int tmp = gcd(m, i);
		if (!id[tmp]) id[tmp] = ++tot, num[tot] = tmp;
		que[id[tmp]].push_back(i);
	}
	for (int i=1;i<=tot;i++) {
		for (int j=1;j<=tot;j++) {
			if (num[j] > num[i] && num[j] % num[i] == 0) {
				AddEdge(i, j); //cout<<i<<' '<<j<<endl;
			}
		}
	}
	//for (int i=1;i<=tot;i++) printf("%d %d\n",in[i],cnt[i]);
	for (int i=1;i<=tot;i++) if (!in[i]) solve(i);
	for (int i=1;i<=tot;i++) if (f[i] == ans) {print(i, 1); break;}
	if (!vis[0]) vout.push_back(0); cout<<vout.size()<<endl;
	for (int i=0;i<=vout.size()-1;i++) printf("%d ",vout[i]);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 5;

int forb[N];

vector<int> cg[N];

int dp[N];
int dpc[N];

pair<pair<long long ,long long>,long long> extended_gcd(long long a, long long b) {
  if(a > b) {
    pair<pair<long long,long long>,long long> p = extended_gcd(b,a); swap(p.first.first,p.first.second);
    return p;
  }
  if(a == 0) return make_pair(pair<long long,long long>(0,1),b); pair<pair<long long,long long>,long long> p = extended_gcd(a, b % a); p.first.first -= (b/a) * p.first.second;
  return p;
}

long long inverseMod(long long a, long long m) {
  pair<pair<long long,long long>,int> p = extended_gcd(a,m); if(p.second != 1) return -1;
  return ((p.first.first % m) + m) % m;
}

int main() {
  int n,m; cin>>n>>m;
  if(m == 1) {
    cout<<1<<endl<<0<<endl;
    return 0;
  }
  for(int i = 0;i < n;i++) {
    int t; scanf("%d",&t);
    forb[t] = 1;
  }
  for(int i = 2;i < m;i++) {
    if(!forb[i]) {
      cg[__gcd(i,m)].push_back(i);
    }
  }

  for(int i = m;i >= 1;i--) {
    dp[i] = -1;
    dpc[i] = 0;
    for(int j = i + i;j < m;j+=i) {
      if(dp[i] == -1)
        dp[i] = j,dpc[i] = dpc[j];
      else if(dpc[j] > dpc[i]) {
        dp[i] = j;
        dpc[i] = dpc[j];
      }
    }
  dpc[i] += cg[i].size();
  }
  vector<int> ans;
  if(!forb[1])
    ans.push_back(1);
  int cc = 1;
  while(cc != -1) {
    for(auto e : cg[cc]) {
      ans.push_back(e);
    }
    cc = dp[cc];
  }
  if(!forb[0])
    ans.push_back(0);
  vector<int> finalAns;
  cout<<ans.size()<<endl;
  cout<<ans[0]<<' ';
  for(int i = 1;i < ans.size();i++) {
    long long gg = __gcd(m,ans[i - 1]);
    long long aa = ans[i - 1]/gg;
    long long bb = ans[i]/gg;
    long long mm = m / gg;
    long long x = (inverseMod(aa,mm) * bb) % mm;
    cout<<x<<' ';
  }
  cout<<endl;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 5;

int forb[N];

vector<int> cg[N];

int dp[N];
int dpc[N];

pair<pair<long long ,long long>,long long> extended_gcd(long long a, long long b) {
  if(a > b) {
    pair<pair<long long,long long>,long long> p = extended_gcd(b,a); swap(p.first.first,p.first.second);
    return p;
  }
  if(a == 0) return make_pair(pair<long long,long long>(0,1),b); pair<pair<long long,long long>,long long> p = extended_gcd(a, b % a); p.first.first -= (b/a) * p.first.second;
  return p;
}

long long inverseMod(long long a, long long m) {
  pair<pair<long long,long long>,int> p = extended_gcd(a,m); if(p.second != 1) return -1;
  return ((p.first.first % m) + m) % m;
}

int main() {
  int n,m; cin>>n>>m;
  for(int i = 0;i < n;i++) {
    int t; scanf("%d",&t);
    forb[t] = 1;
  }
  for(int i = 2;i < m;i++) {
    if(!forb[i]) {
      cg[__gcd(i,m)].push_back(i);
    }
  }
  for(int i = m - 1;i >= 1;i--) {
    dp[i] = -1;
    dpc[i] = 0;
    for(int j = i + i;j < m;j+=i) {
      if(dp[i] == -1)
        dp[i] = j,dpc[i] = dpc[j];
      else if(dpc[j] > dpc[i]) {
        dp[i] = j;
        dpc[i] = dpc[j];
      }
    }
  dpc[i] += cg[i].size();
  }
  vector<int> ans;
  if(!forb[1])
    ans.push_back(1);
  int cc = 1;
  while(cc != -1) {
    for(auto e : cg[cc]) {
      ans.push_back(e);
    }
    cc = dp[cc];
  }
  if(!forb[0])
    ans.push_back(0);
  vector<int> finalAns;
  cout<<ans.size()<<endl;
  cout<<ans[0]<<' ';
  for(int i = 1;i < ans.size();i++) {
    long long gg = __gcd(m,ans[i - 1]);
    long long aa = ans[i - 1]/gg;
    long long bb = ans[i]/gg;
    long long mm = m / gg;
    long long x = (inverseMod(aa,mm) * bb) % mm;
    cout<<x<<' ';
  }
  cout<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[200020];
int v[200020];
int f[200020];
vector<int> z;
int gcd(int x, int y) {
	return y ? gcd(y, x % y) : x;
}
int pow(int x, int y, int p) {
	int re = 1;
	for (; y > 0; y >>= 1) {
		if (y & 1) {
			re = (long long)re * x % p;
		}
		x = (long long)x * x % p;
	}
	return re;
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		a[x] = 1;
	}
	for (int i = 1; i <= m; i++) {
		f[i] = i;
	}
	for (int i = 2; i <= m; i++) {
		if (v[i] > 0) {
			continue;
		}
		for (int j = i; j <= m; j += i) {
			f[j] = f[j] / i * (i - 1);
			if (v[j] == 0) {
				v[j] = i;
			}
		}
	}
	int t = 1;
	int prev = 1;
	int fuck = 1;
	while (true) {
		for (int i = 0; i < m; i++) {
			if (gcd(i, m) == t && a[i] == 0) {
//				if (prev % t == 0) {
//					z.push_back((long long)pow(prev / t, f[m / t] - 1, m / t) * (i / t) % (m / t));
//				} else {
					z.push_back((long long)fuck * pow(prev / (t / fuck), f[m / (t / fuck)] - 1, m / (t / fuck)) * (i / t) % m);
					fuck = 1;
//				}
				prev = i;
			}
		}
		if (t == m) {
			break;
		}
		fuck *= v[m / t];
		t = t * v[m / t];
	}
	printf("%d\n", (int)z.size());
	for (int i = 0; i < z.size(); i++) {
		printf("%d%c", z[i], i == z.size() - 1 ? '\n' : ' ');
	}
//	int tmd = 1;
//	for (int i = 0; i < z.size(); i++) {
//		tmd = (long long)tmd * z[i] % m;
//		printf("%d\n", tmd);
//	}
}


#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[200020];
int v[200020];
int f[200020];
int g[200020];
int mmp[200020];
vector<int> z;
int gcd(int x, int y) {
	return y ? gcd(y, x % y) : x;
}
int pow(int x, int y, int p) {
	int re = 1;
	for (; y > 0; y >>= 1) {
		if (y & 1) {
			re = (long long)re * x % p;
		}
		x = (long long)x * x % p;
	}
	return re;
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++) {
		f[i] = i;
	}
	for (int i = 2; i <= m; i++) {
		if (v[i] > 0) {
			continue;
		}
		for (int j = i; j <= m; j += i) {
			f[j] = f[j] / i * (i - 1);
			if (v[j] == 0) {
				v[j] = i;
			}
		}
	}
	for (int i = 1; i <= m; i++) {
		if (m % i == 0) {
			g[i] = f[m / i];
		}
	}
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		a[x] = 1;
		g[gcd(x, m)]--;
	}

	for (int i = m; i >= 1; i--) {
		if (m % i == 0) {
			int besti = -1;
			for (int j = m; j > i; j--) {
				if (j % i == 0) {
					if (besti == -1 || g[j] > g[besti]) {
						besti = j;
					}
				}
			}
			mmp[i] = besti;
			g[i] += g[besti];
		}
	}
	int t = 1;
	int prev = 1;
	int fuck = 1;
	while (true) {
		for (int i = 0; i < m; i++) {
			if (gcd(i, m) == t && a[i] == 0) {
//				if (prev % t == 0) {
//					z.push_back((long long)pow(prev / t, f[m / t] - 1, m / t) * (i / t) % (m / t));
//				} else {
					z.push_back((long long)fuck * pow(prev / (t / fuck), f[m / (t / fuck)] - 1, m / (t / fuck)) * (i / t) % m);
					fuck = 1;
//				}
				prev = i;
			}
		}
//		printf("%d\n", t);
		if (t == m) {
			break;
		}
//		fuck *= v[m / t];
//		t = t * v[m / t];

//		printf("%d\n", t);
		fuck *= mmp[t] / t;
		t = mmp[t];
//		printf("%d\n", t);
	}
	printf("%d\n", (int)z.size());
	for (int i = 0; i < z.size(); i++) {
		printf("%d%c", z[i], i == z.size() - 1 ? '\n' : ' ');
	}
//	int tmd = 1;
//	for (int i = 0; i < z.size(); i++) {
//		tmd = (long long)tmd * z[i] % m;
//		printf("%d\n", tmd);
//	}
}


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

using ll = long long;

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

pair<int, int> bezout(const int m1, const int m2)
{
    if (m2 == 0) return {1, 0};
    else
    {
        int a1, a2; tie(a1, a2) = bezout(m2, m1 % m2);
        return {a2, a1 - a2*(m1/m2)};
    }
}

int linear_congruence(const int a, const int b, const int m)
{
    const auto d = gcd(a, m);
    auto x = bezout(a, m).first;
    if (x < 0) x += m;
    return int(((ll)x * (b/d)) % m);
}

int main()
{
    int n, m; cin >> n >> m;

    auto allowed = vector<bool>(m+1, true);
    for (auto i = 0; i < n; i++)
    {
        int forbidden; cin >> forbidden;
        if (forbidden == 0) forbidden = m;
        allowed[forbidden] = false;
    }

    auto divisors = vector<int>();
    for (auto x = 1; x <= m; x++) if (m % x == 0)
        divisors.push_back(x);

    auto by_gcd = map<int, vector<int>>();
    for (auto x = 1; x <= m; x++) if (allowed[x])
        by_gcd[gcd(x, m)].push_back(x);

    auto max_lengths = map<int, int>();
    auto predecessors = map<int, int>();
    max_lengths[1] = int(by_gcd[1].size());
    for (const auto d : divisors)
    {
        for (const auto e : divisors) if (e > d && e % d == 0)
        {
            const auto value = int(by_gcd[e].size());
            if (max_lengths[d] + value > max_lengths[e])
            {
                max_lengths[e] = max_lengths[d] + value;
                predecessors[e] = d;
            }
        }
    }

    auto prefixes = vector<int>();
    for (auto d = m; d != 0; d = predecessors[d])
        prefixes.insert(end(prefixes), begin(by_gcd[d]), end(by_gcd[d]));
    prefixes.push_back(1);
    reverse(begin(prefixes), end(prefixes));

    cout << prefixes.size() - 1 << endl;
    for (auto p = next(begin(prefixes)); p != end(prefixes); p++)
        cout << linear_congruence(*prev(p), *p, m) << " ";
    cout << endl;
}


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

using ll = long long;

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

pair<int, int> egcd(const int m1, const int m2)
{
    if (m2 == 0) return {1, 0};
    else
    {
        ll a1, a2; tie(a1, a2) = egcd(m2, m1 % m2);
        return {a2, a1 - a2*(m1/m2)};
    }
}

int main()
{
    int n, m; cin >> n >> m;

    auto allowed = vector<bool>(m, true);
    for (auto i = 0; i < n; i++)
    {
        int forbidden; cin >> forbidden;
        allowed[forbidden] = false;
    }

    auto by_divisor = map<int, vector<int>>();
    for (auto x = 0; x < m; x++)
        if (allowed[x])
            by_divisor[gcd(x, m)].push_back(x);

    auto divisors = vector<int>();
    for (auto d = 1; d <= m; d++)
        if (m % d == 0) divisors.push_back(d);

    auto max_length = map<int, int>();
    auto predecessor = map<int, int>();
    max_length[1] = int(by_divisor[1].size());
    for (const auto d : divisors)
    {
        for (const auto e : divisors) if (e > d && e % d == 0)
        {
            if (max_length[e] < max_length[d] + int(by_divisor[e].size()))
            {
                max_length[e] = max_length[d] + int(by_divisor[e].size());
                predecessor[e] = d;
            }
        }
    }

    auto prefixes = vector<int>();
    for (auto d = m; d != 0; d = predecessor[d])
        prefixes.insert(end(prefixes), begin(by_divisor[d]), end(by_divisor[d]));
    reverse(begin(prefixes), end(prefixes));

    auto prefix = 1;
    auto sequence = vector<int>();
    for (const auto goal : prefixes)
    {
        const auto d = gcd(goal, m) / gcd(prefix, m);
        const auto x = prefix / gcd(prefix, m);
        const auto y = goal / gcd(goal, m);
        int a, b; tie(a, b) = egcd(x, m);
        auto k = ((ll)a * y) % m;
        if (k < 0) k += m;

        const auto s = int(((ll)d*k) % m);
        sequence.push_back(s);
        prefix = int(((ll)prefix * s) % m);
    }

    cout << sequence.size() << endl;
    for (const auto x : sequence) cout << x << " ";
    cout << endl;
}


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

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

pair<int, int> bezout(const int m1, const int m2)
{
    if (m2 == 0) return {1, 0};
    else
    {
        int a1, a2; tie(a1, a2) = bezout(m2, m1%m2);
        return {a2, a1 - a2 * (m1/m2)};
    }
}

int multiply(const int a, const int b, const int m)
{
    const auto x = int(((long long)(a) * b) % m);
    return x >= 0 ? x : x + m;
}

int divide(const int a, const int b, const int m)
{
    const auto d = gcd(b, m);
    assert(a % d == 0);
    return multiply(bezout(b, m).first, a/d, m);
}

int main()
{
    int n, m; cin >> n >> m;

    auto allowed = vector<bool>(m+1, true);
    for (auto i = 0; i < n; i++)
    {
        int forbidden; cin >> forbidden;
        if (forbidden == 0) forbidden = m;
        allowed[forbidden] = false;
    }

    auto divisors = vector<int>();
    for (auto x = 1; x <= m; x++) if (m % x == 0)
        divisors.push_back(x);

    auto by_gcd = map<int, vector<int>>();
    for (auto x = 1; x <= m; x++) if (allowed[x])
        by_gcd[gcd(x, m)].push_back(x);

    auto max_lengths = map<int, int>();
    auto predecessors = map<int, int>();
    max_lengths[1] = int(by_gcd[1].size());
    for (const auto d : divisors)
    {
        for (const auto e : divisors) if (e > d && e % d == 0)
        {
            const auto value = int(by_gcd[e].size());
            if (max_lengths[d] + value > max_lengths[e])
            {
                max_lengths[e] = max_lengths[d] + value;
                predecessors[e] = d;
            }
        }
    }

    auto prefixes = vector<int>();
    for (auto d = m; d != 0; d = predecessors[d])
        prefixes.insert(end(prefixes), begin(by_gcd[d]), end(by_gcd[d]));
    prefixes.push_back(1);
    reverse(begin(prefixes), end(prefixes));

    cout << prefixes.size() - 1 << endl;
    for (auto p = next(begin(prefixes)); p != end(prefixes); p++)
        cout << divide(*p, *prev(p), m) << " ";
    cout << endl;
}


#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;

inline int read(){
	int x = 0, ch = getchar(), f = 1;
	while (!isdigit(ch)){if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}

const int N = 200005;
int n, m, ban[N], rk[N], divs[N], tot;
int in[N], dp[N], id, pre[N];
VI nums[N], to[N];
queue<int> q;

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

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

int calc(int a, int b){ // solve x for ax = b (mod m)
	int x, y, d;
	exgcd(a, m, x, y, d);
	x = (x % m + m) % m;
	assert(x * b / d % m < m && x * b / d % m >= 0);
	return x * b / d % m;
}

int print(int x){
	int las = 1;
	if (pre[x]) las = print(pre[x]);
	RVC(i, nums[x]){
		printf("%d ", calc(las, nums[x][i]));
		las = nums[x][i];
	}
	return las;
}

int main(){
	n = read(), m = read();
	REP(i, 1, n) ban[read()] = 1;
	REP(i, 1, m) if (m % i == 0){
		divs[++tot] = i;
		rk[i] = tot;
	}
	REP(i, 1, m - 1) if (!ban[i]) nums[rk[gcd(i, m)]].pb(i);
	REP(i, 1, tot) REP(j, i + 1, tot)
		if (divs[j] % divs[i] == 0){
			to[i].pb(j); ++in[j];
		}
	REP(i, 1, tot) if (!in[i]){
		q.push(i);
		dp[i] = nums[i].size();
	}
	while (!q.empty()){
		int h = q.front(); q.pop();
		// debug("dp[%d] = %d\n", h, dp[h]);
		if (dp[h] > dp[id]) id = h;
		RVC(i, to[h]){
			int y = to[h][i];
			if (in[y]){
				--in[y];
				if (nums[y].size() && dp[h] + nums[y].size() > dp[y]){
					dp[y] = dp[h] + nums[y].size();
					pre[y] = h;
				}
				if (!in[y]) q.push(y);
			}
		}
	}
	if (ban[0]){
		printf("%d\n", dp[id]);
		print(id);
	}
	else{
		printf("%d\n", dp[id] + 1);
		print(id);
		printf("0\n");
	}
	return 0;
}


#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;

inline int read(){
	int x = 0, ch = getchar(), f = 1;
	while (!isdigit(ch)){if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}

const int N = 200005;
int n, m, ban[N], rk[N], divs[N], tot;
int in[N], dp[N], id, pre[N];
VI nums[N], to[N];
queue<int> q;

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

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

int calc(int a, int b){ // solve x for ax = b (mod m)
	int x, y, d;
	exgcd(a, m, x, y, d);
	x = (x % m + m) % m;
	return x * b / d % m;
}

int print(int x){
	int las = 1;
	if (pre[x]) las = print(pre[x]);
	RVC(i, nums[x]){
		printf("%d ", calc(las, nums[x][i]));
		las = nums[x][i];
	}
	return las;
}

int main(){
	n = read(), m = read();
	REP(i, 1, n) ban[read()] = 1;
	REP(i, 1, m) if (m % i == 0){
		divs[++tot] = i;
		rk[i] = tot;
	}
	REP(i, 1, m - 1) if (!ban[i]) nums[rk[gcd(i, m)]].pb(i);
	REP(i, 1, tot) REP(j, i + 1, tot)
		if (divs[j] % divs[i] == 0){
			to[i].pb(j); ++in[j];
		}
	REP(i, 1, tot) if (!in[i]){
		q.push(i);
		dp[i] = nums[i].size();
	}
	while (!q.empty()){
		int h = q.front(); q.pop();
		// debug("dp[%d] = %d\n", h, dp[h]);
		if (dp[h] > dp[id]) id = h;
		RVC(i, to[h]){
			int y = to[h][i];
			if (in[y]){
				--in[y];
				if (nums[y].size() && dp[h] + nums[y].size() > dp[y]){
					dp[y] = dp[h] + nums[y].size();
					pre[y] = h;
				}
				if (!in[y]) q.push(y);
			}
		}
	}
	if (ban[0]){
		printf("%d\n", dp[id]);
		print(id);
	}
	else{
		printf("%d\n", dp[id] + 1);
		print(id);
		printf("0\n");
	}
	return 0;
}


#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;

inline int read(){
	int x = 0, ch = getchar(), f = 1;
	while (!isdigit(ch)){if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}

const int N = 200005;
int n, m, ban[N], rk[N], divs[N], tot;
int in[N], dp[N], id, pre[N];
VI nums[N], to[N];
queue<int> q;

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

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

int calc(int a, int b){ // solve x for ax = b (mod m)
	int x, y, d;
	exgcd(a, m, x, y, d);
	x = (x % m + m) % m;
	// assert(x * b / d % m < m && x * b / d % m >= 0);
	return 1ll * x * b / d % m;
}

int print(int x){
	int las = 1;
	if (pre[x]) las = print(pre[x]);
	RVC(i, nums[x]){
		printf("%d ", calc(las, nums[x][i]));
		las = nums[x][i];
	}
	return las;
}

int main(){
	n = read(), m = read();
	REP(i, 1, n) ban[read()] = 1;
	REP(i, 1, m) if (m % i == 0){
		divs[++tot] = i;
		rk[i] = tot;
	}
	REP(i, 1, m - 1) if (!ban[i]) nums[rk[gcd(i, m)]].pb(i);
	REP(i, 1, tot) REP(j, i + 1, tot)
		if (divs[j] % divs[i] == 0){
			to[i].pb(j); ++in[j];
		}
	REP(i, 1, tot) if (!in[i]){
		q.push(i);
		dp[i] = nums[i].size();
	}
	while (!q.empty()){
		int h = q.front(); q.pop();
		// debug("dp[%d] = %d\n", h, dp[h]);
		if (dp[h] > dp[id]) id = h;
		RVC(i, to[h]){
			int y = to[h][i];
			if (in[y]){
				--in[y];
				if (nums[y].size() && dp[h] + nums[y].size() > dp[y]){
					dp[y] = dp[h] + nums[y].size();
					pre[y] = h;
				}
				if (!in[y]) q.push(y);
			}
		}
	}
	if (ban[0]){
		printf("%d\n", dp[id]);
		print(id);
	}
	else{
		printf("%d\n", dp[id] + 1);
		print(id);
		printf("0\n");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define PB push_back
#define ll long long
vector<int>ans;
vector<int>G[N],b[N];
int dp[N],pre[N];
bool vis[N];
int gcd(int x,int y)
{
    return y==0?x:gcd(y,x%y);
}
ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(b==0)
    {
        x=1;
        y=0;
        return a;
    }
    ll gcd=exgcd(b,a%b,x,y);
    ll tmp=x;
    x=y;
    y=tmp-a/b*x;
    return gcd;
}
int main()
{
    vis[0]=0;
    int n,m;
    scanf("%d%d",&n,&m);
    while(n--){
        int x;scanf("%d",&x);
        vis[x]=1;
    }
    for(int i=1;i<m;i++)
        if(!vis[i])
            b[gcd(i,m)].PB(i);
    for(int i=1;i<m;i++)
        for(int j=i+i;j<m;j+=i)
           G[i].PB(j);
    int t=0;
    for(int i=1;i<m;i++){
        int h=b[i].size();
        dp[i]=max(h,dp[i]);
        for(int j=0;j<G[i].size();j++){
            int v=G[i][j];
            int tmp=dp[i]+b[v].size();
            if(dp[v]<tmp){
                dp[v]=tmp;
                pre[v]=i;
            }
        }
        if(dp[i]>dp[t])
            t=i;
    }
    while(t){
        for(int i=0;i<b[t].size();i++)
            ans.PB(b[t][i]);
        t=pre[t];
    }
    printf("%d\n",ans.size()+(!vis[0]));
    reverse(ans.begin(),ans.end());
    if(!ans.empty()){
        ll a=ans[0];
        printf("%d",ans[0]);
        for(int i=1;i<ans.size();i++){
            ll x=0,y=0;
            ll b=m;
            int g=exgcd(a,b,x,y);
            // cout<<"ans[i]: "<<ans[i]<<" "<<"g: "<<g<<endl;
            x*=(ans[i]/g);
            x=(x%m+m)%m;
            printf(" %d",x);
            a=a*x%m;
        }
    }
    if(!vis[0])
        puts(" 0");
    else puts("");
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+10;

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

int dp[N],pre[N];
vector<int>g[N],b[N],ans;
bool vis[N];

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        vis[x]=1;
    }
    for(int i=1;i<m;i++){
        if(!vis[i]) b[__gcd(i,m)].push_back(i);
    }
    for(int i=1;i<m;i++){
        for(int j=i+i;j<m;j+=i){
            g[i].push_back(j);
        }
    }
    int t=0;
    for(int i=1;i<m;i++){
        int h=b[i].size();
        dp[i]=max(h,dp[i]);
        for(int j=0;j<g[i].size();j++){
            int v=g[i][j];
            int tem=dp[i]+b[v].size();
            if(dp[v]<tem){
                dp[v]=tem;
                pre[v]=i;
            }
        }
        if(dp[i]>dp[t]) t=i;
    }
    while(t){
        for(int i=0;i<b[t].size();i++){
            ans.push_back(b[t][i]);
        }
        t=pre[t];
    }
    printf("%d\n",ans.size()+(!vis[0]));
    reverse(ans.begin(),ans.end());
    if(!ans.empty()){
    ll a=ans[0];
    printf("%lld",a);
    for(int i=1;i<ans.size();i++){
        ll x=0,y=0;
        ll b=m;
        int g=exgcd(a,b,x,y);
        // cout<<" x: "<<x<<endl;
        // cout<<" ans[i]: "<<ans[i]<<" "<<"g: "<<g<<endl;
        x*=(ans[i]/g);
        x=(x%m+m)%m;
        printf(" %lld",x);
        a=(a*x)%m;
    }
    }
    if(!vis[0]) puts(" 0");
    puts("");
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
const int maxn = 2e5+100;

ll n,m;
ll a[maxn];
set<ll> g;
vi f;
map<ll,ll> divi;
map<ll,ii> din;

ll pown(ll a,ll b,ll mod){
  if(b == 0) return 1;
  ll x = pown(a,b/2,mod);
  x = (x*x)%mod;
  if(b&1) return (x*a)%mod;
  else return x;
}

ii dina(ll a){
  if(!din.count(a)){
    din[a] = ii(0,-1);
    for(int i = 0; i < f.size(); ++i){
      ll b = f[i]*a;
      if(m%b == 0){
        ii x = dina(b);
        if(x.first > din[a].first){
          din[a] = ii(x.first,b);
        }
      }
    }
    din[a].first += divi[a];
  }
  return din[a];
}

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

ll egcd(ll a, ll b, ll& x, ll& y) {
  x = 1; y = 0;
  ll r = 0, s = 1;
  while (b != 0) {
    ll c = a % b, quot = a / b;
    a = b; b = c;
    ll new_r = x - quot * r, new_s = y - quot * s;
    x = r; y = s;
    r = new_r; s = new_s;
  }
  return a;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < n; ++i) g.insert(a[i]);
  ll xx = m;
  for(int i = 1; i <= m; ++i){
    ++divi[gcd(m,i)];
    if(xx%i == 0){
      f.push_back(i);
      while(xx%i) xx /= i;
    }
  }
  for(int i = 0; i < n; ++i) --divi[gcd(m,a[i])];
  ii x = dina(1);
  cout << x.first << '\n';
  ll last = 1;
  ll cl = 1;
  ll cont = 0;
  ll w = x.first;
  while(cont < w){
    if(cl == m){
      if(cont) cout << ' ';
      cout << 0;
      break;
    }
    for(ll i = cl; i <= m; i += cl){
      if(gcd(i,m) == cl){
        if(g.find(i) == g.end()){
          ll aux1,aux2;
          ll g = gcd(m,last);
          ll g2 = egcd(last/g,m/g,aux1,aux2);
          aux1 = (aux1 + m*m)%(m/g);
          if(cont) cout << ' ';
          cout << ((i/g)*aux1)%m;
//           cerr << i << ' ' << aux1 << ' ' << g2 << ' ' << ((i/g)*aux1)%m << '\n';
          last = i;
          cont++;
        }
      }
    }
    cl = x.second;
    x = dina(cl);
  }
  cout << '\n';
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
const int maxn = 2e5+100;

ll n,m;
ll a[maxn];
set<ll> g;
vi f;
map<ll,ll> divi;
map<ll,ii> din;

ll pown(ll a,ll b,ll mod){
  if(b == 0) return 1;
  ll x = pown(a,b/2,mod);
  x = (x*x)%mod;
  if(b&1) return (x*a)%mod;
  else return x;
}

ii dina(ll a){
  if(!din.count(a)){
    din[a] = ii(0,-1);
    for(int i = 0; i < f.size(); ++i){
      ll b = f[i]*a;
      if(m%b == 0){
        ii x = dina(b);
        if(x.first > din[a].first){
          din[a] = ii(x.first,b);
        }
      }
    }
    din[a].first += divi[a];
  }
  return din[a];
}

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

ll egcd(ll a, ll b, ll& x, ll& y) {
  x = 1; y = 0;
  ll r = 0, s = 1;
  while (b != 0) {
    ll c = a % b, quot = a / b;
    a = b; b = c;
    ll new_r = x - quot * r, new_s = y - quot * s;
    x = r; y = s;
    r = new_r; s = new_s;
  }
  return a;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < n; ++i) g.insert(a[i]);
  ll xx = m;
  for(int i = 1; i <= m; ++i){
    ++divi[gcd(m,i)];
    if(xx%i == 0){
      f.push_back(i);
      while(xx%i) xx /= i;
    }
  }
  for(int i = 0; i < n; ++i) --divi[gcd(m,a[i])];
  ii x = dina(1);
  cout << x.first << '\n';
  ll last = 1;
  ll cl = 1;
  ll cont = 0;
  ll w = x.first;
  while(cont < w){
    if(cl == m){
      if(cont) cout << ' ';
      cout << 0;
      break;
    }
    for(ll i = cl; i <= m; i += cl){
      if(gcd(i,m) == cl){
        if(g.find(i) == g.end()){
          ll aux1,aux2;
          ll g = gcd(m,last);
          ll g2 = egcd(last/g,m/g,aux1,aux2);
          aux1 = (aux1 + m*m)%(m/g);
          if(cont) cout << ' ';
          cout << (i*aux1)%m;
//           cerr << i << ' ' << aux1 << ' ' << g2 << ' ' << ((i/g)*aux1)%m << '\n';
          last = i;
          cont++;
        }
      }
    }
    cl = x.second;
    x = dina(cl);
  }
  cout << '\n';
}


#include <bits/stdc++.h>

#define null               ""
#define all(dat)           dat.begin(), dat.end()
#define over(msg)          cout << msg << endl, exit(0);
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

bool vis[200005];
int n, m, sz, phi_n, dp[200005], pre[200005], cur, ans;
map<int, int> id;
vector<int> in[200005], res;

int inline qpow(num a, int b) {
    num res = 1;
    while (b) {
        if (b & 1) {
            res *= a;
            res %= n;
        }
        a *= a;
        a %= n;
        b >>= 1;
    }
    return res % n;
}

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

// solve the equation: ax === b (mod n)
// a ^ phi(n) === 1 (mod n) <== Euler's theorem
// ==> a ^ (phi(n) - 1) === a ^ -1 (mod n) --> (1)
// ax === b (mod n)
// ==> x === b * a ^ -1 (mod n)
// ==> x === b * a ^ (phi(n) - 1) (mod n) <== (1)
// so that one of the solution of the equation ax === b (mod n) is (b * a ^ (phi(n) - 1));
int inline calc(int a, int b) {
    int g = gcd(a, b);
    a /= g;
    b /= g;
    return (num) b * qpow(a, phi_n - 1) % n;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> m >> n;
    cont (i, m) {
        int a;
        cin >> a;
        vis[a] = 1;
    }
    int tmp = phi_n = n;
    circ (i, 2, n) {
        if (tmp % i == 0) {
            phi_n /= i;
            phi_n *= i - 1;
            while (tmp % i == 0) {
                tmp /= i;
            }
        }
    }
    loop (i, n) {
        if (vis[i])  continue;
        in[gcd(i, n)].push_back(i);
    }
    cont (i, n) {
        dp[i] += (int) in[i].size();
        for (int j = i; j <= n; j += i) {
            if (dp[i] > dp[j]) {
                dp[j] = dp[i];
                pre[j] = i;
            }
        }
        if (dp[i] > ans) {
            ans = dp[i];
            cur = i;
        }
    }
    while (cur != 0) {
        for (int u : in[cur]) {
            res.push_back(u);
        }
        cur = pre[cur];
    }
    reverse(all(res));
    cout << ans << endl << res[0] << ' ';
    loop (i, ans - 1) {
        cout << calc(res[i], res[i + 1]) << ' ';
    }
}


#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
using namespace std;

typedef pair <int, int> pii;

const int MAXN = 200005;
const int MAXD = 1005;

int N, M;
bool bio[MAXN];
vector <int> v[MAXN];
int dp[MAXD], dad[MAXD];

void load() {
	scanf("%d%d", &N, &M);
	while (N--) {
		int x;
		scanf("%d", &x);
		bio[x] = true;
	}
}

pii ext_euc(int a, int b) {
	if (!b)
		return {1, 0};
	pii tmp = ext_euc(b, a % b);
	return {-tmp.second, -tmp.first - a / b * tmp.second};
}

int divide(int a, int b) {
	int g = __gcd(b, M);
	assert(!(a % g));
	a /= g;
	b /= g;
	int m = M / g;
	int inv = (ext_euc(b, m).first % m + m) % m;
	return (long long)inv * a % m;
}

void solve() {
	if (M == 1) {
		printf("1\n0\n");
		return;
	}

	vector <int> divs;
	for (int i = 1; i < M; i++) {
		if (!bio[i])
			v[__gcd(i, M)].push_back(i);
		if (!(M % i))
			divs.push_back(i);
	}

	memset(dad, -1, sizeof dad);

	int best = 0;
	for (int i = 0; i < divs.size(); i++) {
		for (int j = 0; j < i; j++)
			if (!(divs[i] % divs[j]) && dp[j] > dp[i]) {
				dp[i] = dp[j];
				dad[i] = j;
			}
		dp[i] += v[divs[i]].size();
		if (dp[i] > dp[best])
			best = i;
	}

	vector <int> seq;
	while (1) {
		seq.push_back(best);
		if (dad[best] == -1)
			break;
		best = dad[best];
	}

	reverse(seq.begin(), seq.end());

	vector <int> sol;
	for (auto it : seq)
		for (auto num : v[divs[it]])
			sol.push_back(num);

	for (int i = (int)sol.size() - 1; i > 0; i--)
		sol[i] = divide(sol[i], sol[i - 1]);
	if (!bio[0])
		sol.push_back(0);

	printf("%d\n", sol.size());
	for (auto it : sol)
		printf("%d ", it);
	puts("");
}

int main() {
	load();
	solve();
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
using namespace std;

typedef pair <int, int> pii;

const int MAXN = 200005;
const int MAXD = 1005;

int N, M;
bool bio[MAXN];
vector <int> v[MAXN];
int dp[MAXD], dad[MAXD];

void load() {
	scanf("%d%d", &N, &M);
	while (N--) {
		int x;
		scanf("%d", &x);
		bio[x] = true;
	}
}

pii ext_euc(int a, int b) {
	if (!b)
		return {1, 0};
	pii tmp = ext_euc(b, a % b);
	return {-tmp.second, -tmp.first - a / b * tmp.second};
}

int divide(int a, int b) {
	int g = __gcd(b, M);
	assert(!(a % g));
	a /= g;
	b /= g;
	int m = M / g;
	int inv = (ext_euc(b, m).first % m + m) % m;
	return (long long)inv * a % m;
}

void solve() {
	vector <int> divs;
	for (int i = 1; i < M; i++) {
		if (!bio[i])
			v[__gcd(i, M)].push_back(i);
		if (!(M % i))
			divs.push_back(i);
	}

	memset(dad, -1, sizeof dad);

	int best = 0;
	for (int i = 0; i < divs.size(); i++) {
		for (int j = 0; j < i; j++)
			if (!(divs[i] % divs[j]) && dp[j] > dp[i]) {
				dp[i] = dp[j];
				dad[i] = j;
			}
		dp[i] += v[divs[i]].size();
		if (dp[i] > dp[best])
			best = i;
	}

	vector <int> seq;
	while (1) {
		seq.push_back(best);
		if (dad[best] == -1)
			break;
		best = dad[best];
	}

	reverse(seq.begin(), seq.end());

	vector <int> sol;
	for (auto it : seq)
		for (auto num : v[divs[it]])
			sol.push_back(num);

	for (int i = (int)sol.size() - 1; i; i--)
		sol[i] = divide(sol[i], sol[i - 1]);
	if (!bio[0])
		sol.push_back(0);

	printf("%d\n", sol.size());
	for (auto it : sol)
		printf("%d ", it);
	puts("");
}

int main() {
	load();
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll big = 1000000007ll;
ll big2 = 1000000009ll;
ll n,m,q,T,k;

vector<ll> divs;
vector<vector<ll> > C(200004 , vector<ll>());
vector<vector<ll> > C2(200004 , vector<ll>());
vector<ll> W;
bool mark[200004] = {0};

ll DP[200004] = {0};

ll gcd(ll i, ll j){
    if(j == 0)return i;
    return gcd(j,i%j);
}

ll dp(ll i){
if(DP[i] != -1)return DP[i];
ll ma = 0;
for(ll c1 = 0; c1 < C2[i].size(); c1++){
    ll a = C2[i][c1];
    ma = max(dp(a), ma);
}
DP[i] = W[i]+ma;
return DP[i];
}

ll upp(ll i, ll j, ll mod){
if(j == 0)return 1ll;
if(j%2 == 0){
    ll h = upp(i,j/2,mod);
    return (h*h)%mod;
}
return (upp(i,j-1,mod)*i)%mod;

}

ll inv(ll a, ll b){
    return 1ll<a ? b - inv(b%a,a)*b/a : 1ll;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c;

    scanf("%d %d" , &n , &m);
    for(ll c1 = 0; c1 < n; c1++){
        scanf("%d" , &a);
        mark[a] = 1;
    }

    if(m == 1){

        cout << "1\n0";
        return 0;
    }

    for(ll c1 = 0; c1 < m+1; c1++){
        W.push_back(0);
    }

    for(ll c1 = 1; c1 < m; c1++){
        if(m%c1 == 0){
            divs.push_back(c1);
            for(ll c2 = 0; c2 < divs.size()-1; c2++){
                if(c1%divs[c2] == 0){
                    C2[divs[c2]].push_back(c1);
                }
            }
        }
        ll g = gcd(m,c1);
        C[g].push_back(c1);
        /*
        ll i;
        for(ll c2 = 0; c2 < divs.size(); c2++){
            if(divs[c2] == g){
                i = c2;
                break;
            }
        }
        */
        W[g]++;
        if(mark[c1])W[g]--;
        DP[c1] = -1;
    }

    ll ma = 0;
    ll mags = 0;
    for(ll c1 = 1; c1 < m; c1++){
        ll g = gcd(c1,m);
         g = c1;
        ll d = dp(g);
        if(d > ma){
            ma = d;
            mags = g;
        }
    }

    vector<ll> A;
    vector<ll> B;
    ll i = mags;
    cout << mags << "\n";
    while(1 == 1){
        A.push_back(i);
        for(ll c1 = 0; c1 < C[i].size(); c1++){
            if(!mark[C[i][c1]])B.push_back(C[i][c1]);
        }
        ll ma2 = 0;
        ll i2 = i;
        for(ll c1 = 0; c1 < C2[i].size(); c1++){
            a = C2[i][c1];
            if(dp(a) > ma2){
                ma2 = dp(a);
                i = a;
            }
        }
        if(i == i2)break;
    }

    if(!mark[0]){
        ma++;
        B.push_back(0);
    }

     ll prod = 1;
    for(ll c1 = 0; c1 < ma; c1++){
        if(c1 == 0 || B[c1] == 0){
            prod *= B[c1];
            prod %= m;
            cout << B[c1]%m << " ";
        }
        else{

            ll g1 = gcd(B[c1-1],m);
            ll g2 = gcd(B[c1],m);

            ll prev = B[c1-1];

            ll m2 = m/g1;
            ll i2 = prev/g1;
            ll j2 = B[c1]/g1;

            ll x2 = (inv(i2,m2) * j2)%m2;

            ll x = (x2)%m;

            prod *= (x)%m;
            prod %= m;

            cout << (x)%m  << " ";

        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll big = 1000000007ll;
ll big2 = 1000000009ll;
int n,m,q,T,k;

vector<ll> divs;
vector<vector<ll> > C(200001 , vector<ll>());
vector<vector<ll> > C2(200001 , vector<ll>());
vector<ll> W;
bool mark[200001] = {0};

ll DP[200001] = {0};

ll gcd(ll i, ll j){
    if(j == 0)return i;
    return gcd(j,i%j);
}

ll dp(ll i){
if(DP[i] != -1)return DP[i];
ll ma = 0;
for(ll c1 = 0; c1 < C2[i].size(); c1++){
    ll a = C2[i][c1];
    ma = max(dp(a), ma);
}
DP[i] = W[i]+ma;
return DP[i];
}

ll upp(ll i, ll j, ll mod){
if(j == 0)return 1;
if(j%2 == 0){
    ll h = upp(i,j/2,mod);
    return (h*h)%mod;
}
return (upp(i,j-1,mod)*i)%mod;

}

ll inv(ll a, ll b){
    return 1<a ? b - inv(b%a,a)*b/a : 1;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c;

    scanf("%d %d" , &n , &m);
    for(ll c1 = 0; c1 < n; c1++){
        scanf("%d" , &a);
        mark[a] = 1;
    }

    for(ll c1 = 0; c1 < m+1; c1++){
        W.push_back(0);
    }

    for(ll c1 = 1; c1 < m; c1++){
        if(m%c1 == 0){
            divs.push_back(c1);
            for(ll c2 = 0; c2 < divs.size()-1; c2++){
                if(c1%divs[c2] == 0){
                    C2[divs[c2]].push_back(c1);
                }
            }
        }
        ll g = gcd(m,c1);
        C[g].push_back(c1);
        /*
        ll i;
        for(ll c2 = 0; c2 < divs.size(); c2++){
            if(divs[c2] == g){
                i = c2;
                break;
            }
        }
        */
        W[g]++;
        if(mark[c1])W[g]--;
        DP[c1] = -1;
    }

    ll ma = 0;
    ll mags = 0;
    for(ll c1 = 1; c1 < m; c1++){
        ll d = dp(c1);
        if(d > ma){
            ma = d;
            mags = c1;
        }
    }

    vector<ll> A;
    vector<ll> B;
    ll i = mags;

    while(1 == 1){
        A.push_back(i);
        for(ll c1 = 0; c1 < C[i].size(); c1++){
            if(!mark[C[i][c1]])B.push_back(C[i][c1]);
        }
        ll ma2 = 0;
        ll i2 = i;
        for(ll c1 = 0; c1 < C2[i].size(); c1++){
            a = C2[i][c1];
            if(dp(a) > ma2){
                ma2 = dp(a);
                i = a;
            }
        }
        if(i == i2)break;
    }

    if(!mark[0]){
        ma++;
        B.push_back(0);
    }

    cout << ma << "\n";
     ll prod = 1;
    for(ll c1 = 0; c1 < ma; c1++){
        if(c1 == 0 || B[c1] == 0){
            prod *= B[c1];
            prod %= m;
            cout << B[c1] << " ";
        }
        else{

            ll g1 = gcd(B[c1-1],m);
            ll g2 = gcd(B[c1],m);

            ll prev = B[c1-1];

            ll m2 = m/g1;
            ll i2 = prev/g1;
            ll j2 = B[c1]/g1;

            ll x2 = (inv(i2,m2) * j2)%m2;

            ll x = (x2)%m;

            prod *= (x)%m;
            prod %= m;

            cout << (x)%m  << " ";

        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll big = 1000000007ll;
ll big2 = 1000000009ll;
ll n,m,q,T,k;

vector<ll> divs;
vector<vector<ll> > C(200004 , vector<ll>());
vector<vector<ll> > C2(200004 , vector<ll>());
vector<ll> W;
bool mark[200004] = {0};

ll DP[200004] = {0};

ll gcd(ll i, ll j){
    if(j == 0)return i;
    return gcd(j,i%j);
}

ll dp(ll i){
if(DP[i] != -1)return DP[i];
ll ma = 0;
for(ll c1 = 0; c1 < C2[i].size(); c1++){
    ll a = C2[i][c1];
    ma = max(dp(a), ma);
}
DP[i] = W[i]+ma;
return DP[i];
}

ll upp(ll i, ll j, ll mod){
if(j == 0)return 1ll;
if(j%2 == 0){
    ll h = upp(i,j/2,mod);
    return (h*h)%mod;
}
return (upp(i,j-1,mod)*i)%mod;

}

ll inv(ll a, ll b){
    return 1ll<a ? b - inv(b%a,a)*b/a : 1ll;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c;

    scanf("%d %d" , &n , &m);
    for(ll c1 = 0; c1 < n; c1++){
        scanf("%d" , &a);
        mark[a] = 1;
    }

    for(ll c1 = 0; c1 < m+1; c1++){
        W.push_back(0);
    }

    for(ll c1 = 1; c1 < m; c1++){
        if(m%c1 == 0){
            divs.push_back(c1);
            for(ll c2 = 0; c2 < divs.size()-1; c2++){
                if(c1%divs[c2] == 0){
                    C2[divs[c2]].push_back(c1);
                }
            }
        }
        ll g = gcd(m,c1);
        C[g].push_back(c1);
        /*
        ll i;
        for(ll c2 = 0; c2 < divs.size(); c2++){
            if(divs[c2] == g){
                i = c2;
                break;
            }
        }
        */
        W[g]++;
        if(mark[c1])W[g]--;
        DP[c1] = -1;
    }

    ll ma = 0;
    ll mags = 0;
    for(ll c1 = 1; c1 < m; c1++){
        ll g = gcd(c1,m);
        ll d = dp(g);
        if(d > ma){
            ma = d;
            mags = g;
        }
    }

    vector<ll> A;
    vector<ll> B;
    ll i = mags;

    while(1 == 1){
        A.push_back(i);
        for(ll c1 = 0; c1 < C[i].size(); c1++){
            if(!mark[C[i][c1]])B.push_back(C[i][c1]);
        }
        ll ma2 = 0;
        ll i2 = i;
        for(ll c1 = 0; c1 < C2[i].size(); c1++){
            a = C2[i][c1];
            if(dp(a) > ma2){
                ma2 = dp(a);
                i = a;
            }
        }
        if(i == i2)break;
    }

    if(!mark[0]){
        ma++;
        B.push_back(0);
    }

    cout << ma << "\n";
     ll prod = 1;
    for(ll c1 = 0; c1 < ma; c1++){
        if(c1 == 0 || B[c1] == 0){
            prod *= B[c1];
            prod %= m;
            cout << B[c1]%m << " ";
        }
        else{

            ll g1 = gcd(B[c1-1],m);
            ll g2 = gcd(B[c1],m);

            ll prev = B[c1-1];

            ll m2 = m/g1;
            ll i2 = prev/g1;
            ll j2 = B[c1]/g1;

            ll x2 = (inv(i2,m2) * j2)%m2;

            ll x = (x2)%m;

            prod *= (x)%m;
            prod %= m;

            cout << (x)%m  << " ";

        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll big = 1000000007ll;
ll big2 = 1000000009ll;
ll n,m,q,T,k;

vector<ll> divs;
vector<vector<ll> > C(200004 , vector<ll>());
vector<vector<ll> > C2(200004 , vector<ll>());
vector<ll> W;
bool mark[200004] = {0};

ll DP[200004] = {0};

ll gcd(ll i, ll j){
    if(j == 0)return i;
    return gcd(j,i%j);
}

ll dp(ll i){
if(DP[i] != -1)return DP[i];
ll ma = 0;
for(ll c1 = 0; c1 < C2[i].size(); c1++){
    ll a = C2[i][c1];
    ma = max(dp(a), ma);
}
DP[i] = W[i]+ma;
return DP[i];
}

ll upp(ll i, ll j, ll mod){
if(j == 0)return 1ll;
if(j%2 == 0){
    ll h = upp(i,j/2,mod);
    return (h*h)%mod;
}
return (upp(i,j-1,mod)*i)%mod;

}

ll inv(ll a, ll b){
    return 1ll<a ? b - inv(b%a,a)*b/a : 1ll;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c;

    cin >> n >> m;
    for(ll c1 = 0; c1 < n; c1++){
        cin >> a;
        mark[a] = 1;
    }

    if(m == 1){

        cout << "1\n0";

    }
    else{
    for(ll c1 = 0; c1 < m+1; c1++){
        W.push_back(0);
    }

    for(ll c1 = 1; c1 < m; c1++){
        if(m%c1 == 0){
            divs.push_back(c1);
            for(ll c2 = 0; c2 < divs.size()-1; c2++){
                if(c1%divs[c2] == 0){
                    C2[divs[c2]].push_back(c1);
                }
            }
        }
        ll g = gcd(m,c1);
        C[g].push_back(c1);
        /*
        ll i;
        for(ll c2 = 0; c2 < divs.size(); c2++){
            if(divs[c2] == g){
                i = c2;
                break;
            }
        }
        */
        W[g]++;
        if(mark[c1])W[g]--;
        DP[c1] = -1;
    }
    DP[0] = -1;
    ll ma = 0;
    ll mags = 0;
    for(ll c1 = 1; c1 < m; c1++){
        ll g = gcd(c1,m);
         //g = c1;
        ll d = dp(g);
        if(d > ma){
            ma = d;
            mags = g;
        }
    }

    vector<ll> A;
    vector<ll> B;
    ll i = mags;

    while(1 == 1){
        A.push_back(i);
        for(ll c1 = 0; c1 < C[i].size(); c1++){
            if(!mark[C[i][c1]])B.push_back(C[i][c1]);
        }
        ll ma2 = 0;
        ll i2 = i;
        for(ll c1 = 0; c1 < C2[i2].size(); c1++){
            a = C2[i2][c1];
            if(dp(a) > ma2){
                ma2 = dp(a);
                i = a;
            }
        }
        if(i == i2)break;
    }

    if(!mark[0]){
        ma++;
        B.push_back(0);
    }

    cout << B.size() << "\n";
     ll prod = 1;
    for(ll c1 = 0; c1 < ma; c1++){
        if(c1 == 0 || B[c1] == 0){
            prod *= B[c1];
            prod %= m;
            cout << B[c1]%m << " ";
        }
        else{

            ll g1 = gcd(B[c1-1],m);
            ll g2 = gcd(B[c1],m);

            ll prev = B[c1-1];

            ll m2 = m/g1;
            ll i2 = prev/g1;
            ll j2 = B[c1]/g1;

            ll x2 = (inv(i2,m2) * j2)%m2;

            ll x = (x2)%m;

            prod *= (x)%m;
            prod %= m;

            cout << (x)%m  << " ";

        }
    }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll big = 1000000007ll;
ll big2 = 1000000009ll;
ll n,m,q,T,k;

vector<ll> divs;
vector<vector<ll> > C(200004 , vector<ll>());
vector<vector<ll> > C2(200004 , vector<ll>());
vector<ll> W;
bool mark[200004] = {0};

ll DP[200004] = {0};

ll gcd(ll i, ll j){
    if(j == 0)return i;
    return gcd(j,i%j);
}

ll dp(ll i){
if(DP[i] != -1)return DP[i];
ll ma = 0;
for(ll c1 = 0; c1 < C2[i].size(); c1++){
    ll a = C2[i][c1];
    ma = max(dp(a), ma);
}
DP[i] = W[i]+ma;
return DP[i];
}

ll upp(ll i, ll j, ll mod){
if(j == 0)return 1ll;
if(j%2 == 0){
    ll h = upp(i,j/2,mod);
    return (h*h)%mod;
}
return (upp(i,j-1,mod)*i)%mod;

}

ll inv(ll a, ll b){
    return 1ll<a ? b - inv(b%a,a)*b/a : 1ll;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c;

    cin >> n >> m;
    for(ll c1 = 0; c1 < n; c1++){
        cin >> a;
        mark[a] = 1;
    }

    if(m == 1){

        cout << "1\n0";

    }
    else{
    for(ll c1 = 0; c1 < m+1; c1++){
        W.push_back(0);
    }

    for(ll c1 = 1; c1 < m; c1++){
        if(m%c1 == 0){
            divs.push_back(c1);
            for(ll c2 = 0; c2 < divs.size()-1; c2++){
                if(c1%divs[c2] == 0){
                    C2[divs[c2]].push_back(c1);
                }
            }
        }
        ll g = gcd(m,c1);
        C[g].push_back(c1);
        /*
        ll i;
        for(ll c2 = 0; c2 < divs.size(); c2++){
            if(divs[c2] == g){
                i = c2;
                break;
            }
        }
        */
        W[g]++;
        if(mark[c1])W[g]--;
        DP[c1] = -1;
    }
    DP[0] = -1;
    ll ma = 0;
    ll mags = 0;
    for(ll c1 = 1; c1 < m; c1++){
        ll g = gcd(c1,m);
         //g = c1;
        ll d = dp(g);
        if(d > ma){
            ma = d;
            mags = g;
        }
    }

    vector<ll> A;
    vector<ll> B;
    ll i = mags;

    while(1 == 1){
        A.push_back(i);
        for(ll c1 = 0; c1 < C[i].size(); c1++){
            if(!mark[C[i][c1]])B.push_back(C[i][c1]);
        }
        ll ma2 = 0;
        ll i2 = i;
        for(ll c1 = 0; c1 < C2[i].size(); c1++){
            a = C2[i][c1];
            if(dp(a) > ma2){
                ma2 = dp(a);
                i = a;
            }
        }
        if(i == i2)break;
    }

    if(!mark[0]){
        ma++;
        B.push_back(0);
    }

    cout << ma << "\n";
     ll prod = 1;
    for(ll c1 = 0; c1 < ma; c1++){
        if(c1 == 0 || B[c1] == 0){
            prod *= B[c1];
            prod %= m;
            cout << B[c1]%m << " ";
        }
        else{

            ll g1 = gcd(B[c1-1],m);
            ll g2 = gcd(B[c1],m);

            ll prev = B[c1-1];

            ll m2 = m/g1;
            ll i2 = prev/g1;
            ll j2 = B[c1]/g1;

            ll x2 = (inv(i2,m2) * j2)%m2;

            ll x = (x2)%m;

            prod *= (x)%m;
            prod %= m;

            cout << (x)%m  << " ";

        }
    }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll big = 1000000007ll;
ll big2 = 1000000009ll;
ll n,m,q,T,k;

vector<ll> divs;
vector<vector<ll> > C(200004 , vector<ll>());
vector<vector<ll> > C2(200004 , vector<ll>());
vector<ll> W;
bool mark[200004] = {0};

ll DP[200004] = {0};

ll gcd(ll i, ll j){
    if(j == 0)return i;
    return gcd(j,i%j);
}

ll dp(ll i){
if(DP[i] != -1)return DP[i];
ll ma = 0;
for(ll c1 = 0; c1 < C2[i].size(); c1++){
    ll a = C2[i][c1];
    ma = max(dp(a), ma);
}
DP[i] = W[i]+ma;
return DP[i];
}

ll upp(ll i, ll j, ll mod){
if(j == 0)return 1ll;
if(j%2 == 0){
    ll h = upp(i,j/2,mod);
    return (h*h)%mod;
}
return (upp(i,j-1,mod)*i)%mod;

}

ll inv(ll a, ll b){
    return 1ll<a ? b - inv(b%a,a)*b/a : 1ll;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c;

    cin >> n >> m;
    for(ll c1 = 0; c1 < n; c1++){
        cin >> a;
        mark[a] = 1;
    }

    if(m == 1){

        cout << "1\n0";

    }
    else{
    for(ll c1 = 0; c1 < m+1; c1++){
        W.push_back(0);
    }

    for(ll c1 = 1; c1 < m; c1++){
        if(m%c1 == 0){
            divs.push_back(c1);
            for(ll c2 = 0; c2 < divs.size()-1; c2++){
                if(c1%divs[c2] == 0){
                    C2[divs[c2]].push_back(c1);
                }
            }
        }
        ll g = gcd(m,c1);
        C[g].push_back(c1);
        /*
        ll i;
        for(ll c2 = 0; c2 < divs.size(); c2++){
            if(divs[c2] == g){
                i = c2;
                break;
            }
        }
        */
        W[g]++;
        if(mark[c1])W[g]--;
        DP[c1] = -1;
    }
    DP[0] = -1;
    ll ma = 0;
    ll mags = 0;
    for(ll c1 = 1; c1 < m; c1++){
        ll g = gcd(c1,m);
         //g = c1;
        ll d = dp(g);
        if(d > ma){
            ma = d;
            mags = g;
        }
    }

    vector<ll> A;
    vector<ll> B;
    ll i = mags;

    while(1 == 1){
        A.push_back(i);
        for(ll c1 = 0; c1 < C[i].size(); c1++){
            if(!mark[C[i][c1]])B.push_back(C[i][c1]);
        }
        ll ma2 = 0;
        ll i2 = i;
        for(ll c1 = 0; c1 < C2[i].size(); c1++){
            a = C2[i][c1];
            if(dp(a) > ma2){
                ma2 = dp(a);
                i = a;
            }
        }
        if(i == i2)break;
    }

    if(!mark[0]){
        ma++;
        B.push_back(0);
    }

    cout << B.size() << "\n";
     ll prod = 1;
    for(ll c1 = 0; c1 < ma; c1++){
        if(c1 == 0 || B[c1] == 0){
            prod *= B[c1];
            prod %= m;
            cout << B[c1]%m << " ";
        }
        else{

            ll g1 = gcd(B[c1-1],m);
            ll g2 = gcd(B[c1],m);

            ll prev = B[c1-1];

            ll m2 = m/g1;
            ll i2 = prev/g1;
            ll j2 = B[c1]/g1;

            ll x2 = (inv(i2,m2) * j2)%m2;

            ll x = (x2)%m;

            prod *= (x)%m;
            prod %= m;

            cout << (x)%m  << " ";

        }
    }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll big = 1000000007ll;
ll big2 = 1000000009ll;
ll n,m,q,T,k;

vector<ll> divs;
vector<vector<ll> > C(200004 , vector<ll>());
vector<vector<ll> > C2(200004 , vector<ll>());
vector<ll> W;
bool mark[200004] = {0};

ll DP[200004] = {0};

ll gcd(ll i, ll j){
    if(j == 0)return i;
    return gcd(j,i%j);
}

ll dp(ll i){
if(DP[i] != -1)return DP[i];
ll ma = 0;
for(ll c1 = 0; c1 < C2[i].size(); c1++){
    ll a = C2[i][c1];
    ma = max(dp(a), ma);
}
DP[i] = W[i]+ma;
return DP[i];
}

ll upp(ll i, ll j, ll mod){
if(j == 0)return 1ll;
if(j%2 == 0){
    ll h = upp(i,j/2,mod);
    return (h*h)%mod;
}
return (upp(i,j-1,mod)*i)%mod;

}

ll inv(ll a, ll b){
    return 1ll<a ? b - inv(b%a,a)*b/a : 1ll;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c;

    scanf("%d %d" , &n , &m);
    for(ll c1 = 0; c1 < n; c1++){
        scanf("%d" , &a);
        mark[a] = 1;
    }

    if(m == 1){

        cout << "1\n0";

    }
    else{
    for(ll c1 = 0; c1 < m+1; c1++){
        W.push_back(0);
    }

    for(ll c1 = 1; c1 < m; c1++){
        if(m%c1 == 0){
            divs.push_back(c1);
            for(ll c2 = 0; c2 < divs.size()-1; c2++){
                if(c1%divs[c2] == 0){
                    C2[divs[c2]].push_back(c1);
                }
            }
        }
        ll g = gcd(m,c1);
        C[g].push_back(c1);
        /*
        ll i;
        for(ll c2 = 0; c2 < divs.size(); c2++){
            if(divs[c2] == g){
                i = c2;
                break;
            }
        }
        */
        W[g]++;
        if(mark[c1])W[g]--;
        DP[c1] = -1;
    }

    ll ma = 0;
    ll mags = 0;
    for(ll c1 = 1; c1 < m; c1++){
        ll g = gcd(c1,m);
         g = c1;
        ll d = dp(g);
        if(d > ma){
            ma = d;
            mags = g;
        }
    }

    vector<ll> A;
    vector<ll> B;
    ll i = mags;

    while(1 == 1){
        A.push_back(i);
        for(ll c1 = 0; c1 < C[i].size(); c1++){
            if(!mark[C[i][c1]])B.push_back(C[i][c1]);
        }
        ll ma2 = 0;
        ll i2 = i;
        for(ll c1 = 0; c1 < C2[i].size(); c1++){
            a = C2[i][c1];
            if(dp(a) > ma2){
                ma2 = dp(a);
                i = a;
            }
        }
        if(i == i2)break;
    }

    if(!mark[0]){
        ma++;
        B.push_back(0);
    }

    cout << B.size() << "\n";
     ll prod = 1;
    for(ll c1 = 0; c1 < ma; c1++){
        if(c1 == 0 || B[c1] == 0){
            prod *= B[c1];
            prod %= m;
            cout << B[c1]%m << " ";
        }
        else{

            ll g1 = gcd(B[c1-1],m);
            ll g2 = gcd(B[c1],m);

            ll prev = B[c1-1];

            ll m2 = m/g1;
            ll i2 = prev/g1;
            ll j2 = B[c1]/g1;

            ll x2 = (inv(i2,m2) * j2)%m2;

            ll x = (x2)%m;

            prod *= (x)%m;
            prod %= m;

            cout << (x)%m  << " ";

        }
    }
    }
    return 0;
}


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

vector<int> pr, pchk;

void getPr() {
    pchk = vector<int>(200002, 0);
    for(int i = 2; i < 200002; i++) {
        if(pchk[i]) continue;
        pr.push_back(i);
        int mul = 2;
        while(i * mul < 200002) {
            pchk[i * mul] = 1;
            mul++;
        }
    }
}

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

int N, M;

int pi;
vector<int> fac;

void getPi() {

    for(int i = 0; i < pr.size(); i++) {
        if(M % pr[i] == 0) fac.push_back(pr[i]);
    }

    pi = M;

    for(int i = 0; i < fac.size(); i++) {
        pi /= fac[i];
        pi *= fac[i] - 1;
    }
}

int po(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = (long long)ret * x % M;
        x = (long long)x * x % M;
        n >>= 1;
    }
    return ret;
}

int modInv(int x) { return po(x, pi - 1); }

vector<int> di, chk, cnt;
vector<vector<int> > L;

map<int, int> dx;

vector<int> cc;

int dp(int gidx) {
    int &ret = cc[gidx];
    if(ret != -1) return ret;

    ret = 0;

    for(int i = 0; i < di.size(); i++) {
        if(i != gidx && di[i] % di[gidx] == 0) {
            ret = max(ret, cnt[i] + dp(i));
        }
    }

    return ret;
}

void dfs(int gidx, int pre) {

    int pos = 0;

    if(pre == -1) {
        printf("%d ", L[gidx][0]);
        pre = L[gidx][0];

        pos++;
    }

    for(int i = pos; i < L[gidx].size(); i++) {

        int m = (pre % di[gidx]? di[gidx] / gcd(pre, M) : 1);
        int a = L[gidx][i] / di[gidx];
        int b = pre * m / di[gidx];
        m *= (long long)a * modInv(b) % M;
        m %= M;

        printf("%d ", m);

        pre = L[gidx][i];
    }

    for(int i = 0; i < di.size(); i++) {
        if(i != gidx && di[i] % di[gidx] == 0) {
            dfs(i, pre);
            return;
        }
    }
}

int main() {
    getPr();

    scanf("%d %d", &N, &M);

    chk = vector<int>(M, 0);

    for(int i = 0; i < N; i++) {
        int t; scanf("%d", &t);
        chk[t] = 1;
    }

    if(M == 1) {
        printf("1\n0");
        return 0;
    }

    for(int i = 1; i <= sqrt(M); i++) {
        if(M % i == 0) {
            di.push_back(i);
            if(i * i != M) di.push_back(M / i);
        }
    }

    sort(di.begin(), di.end());

    for(int i = 0; i < di.size(); i++) dx[ di[i] ] = i;

    cnt = vector<int>(di.size(), 0);
    L.resize(di.size());

    for(int i = 0; i < M; i++) {
        if(chk[i]) continue;

        cnt[ dx[ gcd(i, M) ] ]++;
        L[ dx[ gcd(i, M) ] ].push_back(i);
    }

    cc = vector<int>(di.size(), -1);

    printf("%d\n", cnt[0] + dp(0));

    getPi();

    dfs(0, -1);
}


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

vector<int> pr, pchk;

void getPr() {
    pchk = vector<int>(200002, 0);
    for(int i = 2; i < 200002; i++) {
        if(pchk[i]) continue;
        pr.push_back(i);
        int mul = 2;
        while(i * mul < 200002) {
            pchk[i * mul] = 1;
            mul++;
        }
    }
}

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

int N, M;

int pi;
vector<int> fac;

void getPi() {

    for(int i = 0; i < pr.size(); i++) {
        if(M % pr[i] == 0) fac.push_back(pr[i]);
    }

    pi = M;

    for(int i = 0; i < fac.size(); i++) {
        pi /= fac[i];
        pi *= fac[i] - 1;
    }
}

int po(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = (long long)ret * x % M;
        x = (long long)x * x % M;
        n >>= 1;
    }
    return ret;
}

int modInv(int x) { return po(x, pi - 1); }

vector<int> di, chk, cnt;
vector<vector<int> > L;

map<int, int> dx;

vector<int> cc;

int dp(int gidx) {
    int &ret = cc[gidx];
    if(ret != -1) return ret;

    ret = 0;

    for(int i = 0; i < di.size(); i++) {
        if(i != gidx && di[i] % di[gidx] == 0) {
            ret = max(ret, cnt[i] + dp(i));
        }
    }

    return ret;
}

void dfs(int gidx, int pre) {

    int pos = 0;

    if(pre == -1) {
        printf("%d ", L[gidx][0]);
        pre = L[gidx][0];

        pos++;
    }

    for(int i = pos; i < L[gidx].size(); i++) {

        int m = (pre % di[gidx]? di[gidx] / gcd(pre, M) : 1);
        int a = L[gidx][i] / di[gidx];
        int b = (long long) pre * m / di[gidx];
        m *= (long long)a * modInv(b) % M;
        m %= M;

        printf("%d ", m);

        pre = L[gidx][i];
    }

    for(int i = 0; i < di.size(); i++) {
        if(i != gidx && di[i] % di[gidx] == 0) {
            dfs(i, pre);
            return;
        }
    }
}

int main() {
    getPr();

    scanf("%d %d", &N, &M);

    chk = vector<int>(M, 0);

    for(int i = 0; i < N; i++) {
        int t; scanf("%d", &t);
        chk[t] = 1;
    }

    if(M == 1) {
        printf("1\n0");
        return 0;
    }

    for(int i = 1; i <= sqrt(M); i++) {
        if(M % i == 0) {
            di.push_back(i);
            if(i * i != M) di.push_back(M / i);
        }
    }

    sort(di.begin(), di.end());

    for(int i = 0; i < di.size(); i++) dx[ di[i] ] = i;

    cnt = vector<int>(di.size(), 0);
    L.resize(di.size());

    for(int i = 0; i < M; i++) {
        if(chk[i]) continue;

        cnt[ dx[ gcd(i, M) ] ]++;
        L[ dx[ gcd(i, M) ] ].push_back(i);
    }

    cc = vector<int>(di.size(), -1);

    printf("%d\n", cnt[0] + dp(0));

    getPi();

    dfs(0, -1);
}


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

vector<int> pr, pchk;

void getPr() {
    pchk = vector<int>(200002, 0);
    for(int i = 2; i < 200002; i++) {
        if(pchk[i]) continue;
        pr.push_back(i);
        int mul = 2;
        while(i * mul < 200002) {
            pchk[i * mul] = 1;
            mul++;
        }
    }
}

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

int N, M;

int pi;
vector<int> fac;

void getPi() {

    for(int i = 0; i < pr.size(); i++) {
        if(M % pr[i] == 0) fac.push_back(pr[i]);
    }

    pi = M;

    for(int i = 0; i < fac.size(); i++) {
        pi /= fac[i];
        pi *= fac[i] - 1;
    }
}

int po(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = (long long)ret * x % M;
        x = (long long)x * x % M;
        n >>= 1;
    }
    return ret;
}

int modInv(int x) { return po(x, pi - 1); }

vector<int> di, chk, cnt;
vector<vector<int> > L;

map<int, int> dx;

vector<int> cc;

int dp(int gidx) {
    int &ret = cc[gidx];
    if(ret != -1) return ret;

    ret = 0;

    for(int i = 0; i < di.size(); i++) {
        if(i != gidx && di[i] % di[gidx] == 0) {
            ret = max(ret, cnt[i] + dp(i));
        }
    }

    return ret;
}

void dfs(int gidx, int pre) {

    int pos = 0;

    if(pre == -1 && L[gidx].size()) {
        printf("%d ", L[gidx][0]);
        pre = L[gidx][0];
        pos++;
    }

    for(int i = pos; i < L[gidx].size(); i++) {

        long long m = (long long)di[gidx] / gcd(pre, M);
        long long a = (long long)L[gidx][i] / di[gidx];
        long long b = (long long) pre * m / di[gidx];
        m *= (long long)a * modInv(b) % M;
        m %= M;

        printf("%I64d ", m);

        pre = L[gidx][i];
    }

    for(int i = 0; i < di.size(); i++) {
        if(i != gidx && di[i] % di[gidx] == 0) {
            dfs(i, pre);
            return;
        }
    }
}

int main() {
    getPr();

    scanf("%d %d", &N, &M);

    chk = vector<int>(M, 0);

    for(int i = 0; i < N; i++) {
        int t; scanf("%d", &t);
        chk[t] = 1;
    }

    if(M == 1) {
        printf("1\n0");
        return 0;
    }

    for(int i = 1; i <= sqrt(M); i++) {
        if(M % i == 0) {
            di.push_back(i);
            if(i * i != M) di.push_back(M / i);
        }
    }

    sort(di.begin(), di.end());

    for(int i = 0; i < di.size(); i++) dx[ di[i] ] = i;

    cnt = vector<int>(di.size(), 0);
    L.resize(di.size());

    for(int i = 0; i < M; i++) {
        if(chk[i]) continue;

        cnt[ dx[ gcd(i, M) ] ]++;
        L[ dx[ gcd(i, M) ] ].push_back(i);
    }

    cc = vector<int>(di.size(), -1);

    printf("%d\n", cnt[0] + dp(0));

    getPi();

    dfs(0, -1);
}


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

vector<int> pr, pchk;

void getPr() {
    pchk = vector<int>(200002, 0);
    for(int i = 2; i < 200002; i++) {
        if(pchk[i]) continue;
        pr.push_back(i);
        int mul = 2;
        while(i * mul < 200002) {
            pchk[i * mul] = 1;
            mul++;
        }
    }
}

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

int N, M;

int pi;
vector<int> fac;

void getPi() {

    for(int i = 0; i < pr.size(); i++) {
        if(M % pr[i] == 0) fac.push_back(pr[i]);
    }

    pi = M;

    for(int i = 0; i < fac.size(); i++) {
        pi /= fac[i];
        pi *= fac[i] - 1;
    }
}

int po(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = (long long)ret * x % M;
        x = (long long)x * x % M;
        n >>= 1;
    }
    return ret;
}

int modInv(int x) { return po(x, pi - 1); }

vector<int> di, chk, cnt;
vector<vector<int> > L;

map<int, int> dx;

vector<int> cc;

int dp(int gidx) {
    int &ret = cc[gidx];
    if(ret != -1) return ret;

    ret = 0;

    for(int i = 0; i < di.size(); i++) {
        if(i != gidx && di[i] % di[gidx] == 0) {
            ret = max(ret, cnt[i] + dp(i));
        }
    }

    return ret;
}

void dfs(int gidx, int pre) {

    int pos = 0;

    if(pre == -1 && L[gidx].size()) {
        printf("%d ", L[gidx][0]);
        pre = L[gidx][0];
        pos++;
    }

    for(int i = pos; i < L[gidx].size(); i++) {

        long long m = (long long)di[gidx] / gcd(pre, M);
        long long a = (long long)L[gidx][i] / di[gidx];
        long long b = (long long)pre * m / di[gidx];

        m *= (long long)a * modInv(b) % M;
        m %= M;

        printf("%I64d ", m);

        pre = L[gidx][i];
    }

    for(int i = 0; i < di.size(); i++) {
        if(i != gidx && di[i] % di[gidx] == 0 && dp(gidx) == cnt[i] + dp(i)) {
            dfs(i, pre);
            return;
        }
    }
}

int main() {
    getPr();

    scanf("%d %d", &N, &M);

    chk = vector<int>(M, 0);

    for(int i = 0; i < N; i++) {
        int t; scanf("%d", &t);
        chk[t] = 1;
    }

    if(M == 1) {
        printf("1\n0");
        return 0;
    }

    for(int i = 1; i <= M; i++) {
        if(M % i == 0) {
            di.push_back(i);
        }
    }

    for(int i = 0; i < di.size(); i++) dx[ di[i] ] = i;

    cnt = vector<int>(di.size(), 0);
    L.resize(di.size());

    for(int i = 0; i < M; i++) {
        if(chk[i]) continue;

        cnt[ dx[ gcd(i, M) ] ]++;
        L[ dx[ gcd(i, M) ] ].push_back(i);
    }

    cc = vector<int>(di.size(), -1);

    printf("%d\n", cnt[0] + dp(0));

    getPi();

    dfs(0, -1);
}


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

vector<int> pr, pchk;

void getPr() {
    pchk = vector<int>(200002, 0);
    for(int i = 2; i < 200002; i++) {
        if(pchk[i]) continue;
        pr.push_back(i);
        int mul = 2;
        while(i * mul < 200002) {
            pchk[i * mul] = 1;
            mul++;
        }
    }
}

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

int N, M;

int pi;
vector<int> fac;

void getPi() {

    for(int i = 0; i < pr.size(); i++) {
        if(M % pr[i] == 0) fac.push_back(pr[i]);
    }

    pi = M;

    for(int i = 0; i < fac.size(); i++) {
        pi /= fac[i];
        pi *= fac[i] - 1;
    }
}

int po(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = (long long)ret * x % M;
        x = (long long)x * x % M;
        n >>= 1;
    }
    return ret;
}

int modInv(int x) { return po(x, pi - 1); }

vector<int> di, chk, cnt;
vector<vector<int> > L;

map<int, int> dx;

vector<int> cc;

int dp(int gidx) {
    int &ret = cc[gidx];
    if(ret != -1) return ret;

    ret = 0;

    for(int i = 0; i < di.size(); i++) {
        if(i != gidx && di[i] % di[gidx] == 0) {
            ret = max(ret, cnt[i] + dp(i));
        }
    }

    return ret;
}

void dfs(int gidx, int pre) {

    int pos = 0;

    if(pre == -1) {
        printf("%d ", L[gidx][0]);
        pre = L[gidx][0];

        pos++;
    }

    for(int i = pos; i < L[gidx].size(); i++) {

        long long m = (long long)di[gidx] / gcd(pre, M);
        long long a = (long long)L[gidx][i] / di[gidx];
        long long b = (long long) pre * m / di[gidx];
        m *= (long long)a * modInv(b) % M;
        m %= M;

        printf("%I64d ", m);

        pre = L[gidx][i];
    }

    for(int i = 0; i < di.size(); i++) {
        if(i != gidx && di[i] % di[gidx] == 0) {
            dfs(i, pre);
            return;
        }
    }
}

int main() {
    getPr();

    scanf("%d %d", &N, &M);

    chk = vector<int>(M, 0);

    for(int i = 0; i < N; i++) {
        int t; scanf("%d", &t);
        chk[t] = 1;
    }

    if(M == 1) {
        printf("1\n0");
        return 0;
    }

    for(int i = 1; i <= sqrt(M); i++) {
        if(M % i == 0) {
            di.push_back(i);
            if(i * i != M) di.push_back(M / i);
        }
    }

    sort(di.begin(), di.end());

    for(int i = 0; i < di.size(); i++) dx[ di[i] ] = i;

    cnt = vector<int>(di.size(), 0);
    L.resize(di.size());

    for(int i = 0; i < M; i++) {
        if(chk[i]) continue;

        cnt[ dx[ gcd(i, M) ] ]++;
        L[ dx[ gcd(i, M) ] ].push_back(i);
    }

    cc = vector<int>(di.size(), -1);

    printf("%d\n", cnt[0] + dp(0));

    getPi();

    dfs(0, -1);
}