#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#define ll long long
#define str string
#define ld long double
#define pb push_back
#define pf push_front
#define pob pop_back();
#define pof pop_front();
#define in insert
#define fi first
#define se second
#define begin begin()
#define end end()
#define size size()
#define rend rend()
#define rbegin rbegin()
#define ret return
#define ull unsigned long long
#define all(a) a.begin , a.end
#define gcd(a , b) __gcd(a , b)
#define lcm(a , b) (a * b) / gcd(a , b)
#define all(a) a.begin , a.end
#define friopen freopen ("in.in", "r", stdin); freopen("out.out", "w", stdout);
using namespace std;

///                         ERASE
/*




str --  a.erase(index nachala , kolichesvo simvolov);


deque , vector -- a.erase(a.begin + index nachala , a.begin + index konca + 1);




*/




const ld EPS = 0.00000000000001;

void kol_a()
{
    ll n , m , i , j , v;
    cin >> n >> m;
    deque<ll> ans;
    map<ll, ll> d;
    for (i = 1 ; i <= m ; i ++)
    {
        cin >> v;
        d[v] ++;
        if (d[v] >= n)
        {
            d[v] = -1e9;
            ans.pb(v);
        }
    }
    cout << ans.size << '\n';
    for (auto x : ans) cout << x << " ";

}


void kol_b()
{
    ull n , s;
    cin >> n;
    s = n * (n - 1) / 2;
    cout << (n == 3 ? 1 : s) << '\n';
}

int main()
{
    FAST
    ll _ = 1;
    //fflush(stdout);
    //cin >> _;
    while(_ --) kol_a();
}

/*

*/
