#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;

void solve() {
    int n , m;
    cin >> n >> m;
    vector <int> uslugi(m);
    for (int i = 0; i < m; ++i)
        cin >> uslugi[i];
    sort(uslugi.begin() , uslugi.end());
    int x = 1;
    vector <int> variki;
    variki.push_back(-99999);
    bool albertlox = false;
    for (int i = 0; i < m; ++i) {
        if (uslugi[i] == uslugi[i+1] and !albertlox)
            x = x + 1;
        else {
            x = 1;
            albertlox = false;
        }
        if (n <= x and variki[variki.size() - 1] != uslugi[i] ){
            variki.push_back(uslugi[i]);
            albertlox = true;
        }



    }
    cout << variki.size() - 1 << "\n";
    for (int i = 1; i < variki.size(); ++i) {
        cout << variki[i] << " ";

    }
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#endif
    int t = 1;
//    cin >> t;
    while (t--) solve();
}

