/*
It is code Zhanabergen Abdurroshid :))))
*/
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define m_p make_pair
#define p_b push_back
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<ll>
#define vii vector<pii>
#define viii vector<pair<int,pii> >
#define si set<int>
#define sii multiset<pii>
#define siii set<pair<int,pii> >
#define F first
#define S second
#define pre precision
#define n_per next_permutation
#define sz size()
#define all(x) x.begin(),x.end()
#define RUN ios_base::sync_with_stdio(false);cin.tie(0);
#define OPEN freopen("rmq.in","r",stdin);freopen("rmq.out","w",stdout)
using namespace std;
ll fl(){
	ll a;
	cin>>a;
	return a;
}
const ll N = 7e6 + 9;
const ll INF = 1e18 + 9, MOD = 1e9 + 7;
main(){
	RUN;
	//OPEN;
	int n = fl(), m = fl();
	int a[m + 9];
	for(int i=1;i<=m;i++)a[i] = fl();
	sort(a+1,a+m+1);
	int cnt = 1;
	vi v;
	for(int i=2;i<=m;i++){
		if(a[i]==a[i-1])cnt++;
		else{
			if(cnt>=n)v.p_b(a[i-1]);
			cnt = 1;
		}
	}
	if(cnt>=n)v.p_b(a[m]);
	cout<<v.sz<<'\n';
	for(int i:v)cout<<i<<" ";
	return 0;
}
