#include <bits/stdc++.h>
#define ll long long
#define all(a) a.begin(), a.end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define ull unsigned long long
#define ld long double
#define files freopen("HelpMe.in", "r", stdin), freopen("HelpMe.out", "w", stdout)
using namespace std;
const ll mod = 1e9+7;
const ll N = 3e5 + 10;
const ll P = 337ll;
const ld EPS = 1e-9;
const ll block = 400;
ll arr[N];
int main() {
	ios::sync_with_stdio(false);
  	cin.tie(NULL);
  	//freopen("race.in","r",stdin);
  	//freopen("race.out","w",stdout);
  	ll n, m, cnt = 0, pred;
  	cin >> n >> m;
  	for(ll i = 0; i < m; i++){
  		cin >> arr[i];
  	}
  	sort(arr, arr + m);
  	vector <ll> ans;
  	for(ll i = 0; i < m; i++){
  		if(i > 0){
  			if(arr[i] != pred){
  				if(cnt >= n) ans.pb(pred);
  				cnt = 0;
  			}
  		}
  		pred = arr[i];
  		cnt++;
  	}
  	if(cnt >= n) ans.pb(pred);
  	cout << (ll)ans.size() << endl;
  	for(auto u : ans){
  		cout << u << " ";
  	}
  return 0;
}
// equal, min, max, 1, random
/*
******
******
******
******
******
******
*/
