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

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n, m;

    cin >> n >> m;

    vector <ll> v(m);
    for (int i = 0; i < m; i++)
        cin >> v[i];
    sort(v.begin(), v.end());
    v.push_back(1e11);

    ll ok = 1;
    vector <ll> w;
    for (int i = 0; i < v.size(); i++) {
        if (i && v[i - 1] == v[i]) {
            ok++;
        }
        else if (ok >= n) {
            w.push_back(v[i - 1]);
            ok = 1;
        }
        else {
            ok = 1;
        }
    }

    cout << w.size() << "\n";
    for (auto i : w)
        cout << i << " ";

    return 0;
}
