#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>

#define endl '\n'

bool Count(std::vector<unsigned> arr, unsigned value, unsigned i, unsigned n) {
    unsigned count = 0;
    bool res = false;
    for (unsigned j = 0; j < i; j++)
        {
            if (value == arr[j]) {
                count ++;
            }
            if (count >= n){
                res = true;
                break;
            }
        }
    return res;
}

int main() {

    unsigned n, m, value;
    std::cin >> n >> m;
    --n;
    std::vector<unsigned> was;
    std::unordered_set<unsigned> res;

    for (unsigned i = 0; i < m; i++)
    {
        std::cin >> value;
        
        if (n == 0 || Count(was, value, i, n)) {
            res.insert(value);     
        } else {
            was.push_back(value);
        }
    }
    
    std::cout << res.size() << endl; 
    for (unsigned i : res)
    {
        std::cout << i << ' ';
    }
    return 0;
}

