#include <iostream>
#include <algorithm>
#include <set>

using namespace std;

int a[3000000];

int main()
{
    long long n, m, cnt = 0;
    set<int> st;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> a[i];
    }
    sort (a, a + m);
    if (n > 1) {
        for (int i = 1; i <= m; i++) {
            if (a[i] == a[i - 1]) {
                cnt++;
                if (cnt + 1 >= n) {
                    st.insert(a[i]);
                    cnt = 0;
                }
            }
        }
    }
    else {
        for (int i = 1; i <= m; i++) {
            if (a[i] != a[i - 1]) {
                st.insert(a[i]);
            }
        }
    }
    cout << st.size() << "\n";
    for (auto i: st) {
        cout << i << " ";
    }
    return 0;
}
