// By ObeliX
#include <bits/stdc++.h>
#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include <unordered_map>
#include <cstddef>
#include <cassert>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>

using namespace std;
const long long INF = 1e18;
const long long mod = 998244353;
const long long N = 1e6;
const long long M = 1ll << 32 ;
const double eps = 1e-6;
string alph = "abcdefghijklmnopqrstuvwxyz";
// ||

long long n , m;
long long a[N];

int main(){
    //freopen( "cinema.in" , "r" , stdin );
    //freopen( "cinema.out" , "w" , stdout );
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for ( int i = 1 ; i <= m ; i++ ){
        cin >> a[i];
    }
    sort( a + 1 , a + 1 + m );
    long long cnt = 1;
    vector <long long> v;
    v.clear();
    for ( int i = 2 ; i <= m ; i++ ) {
        if ( a[i] != a[i-1] ) {
            if ( cnt >= n ) {
                v.push_back( a[i-1] );
                cnt = 1;
            }
            else {
                cnt = 1;
                continue;
            }
        }
        else {
            cnt++;
        }
    }
    if ( cnt >= n ) {
        v.push_back( a[m] );
    }
    cout << v.size() << endl;
    for ( auto it : v ) {
        cout << it << " ";
    }
}
