#include <iostream>
#include <vector>

using namespace std;

int main(){
	long long n, k, p=1; cin >> n >> k;
	vector<int> a(2*n+1);
	vector<int> b(0);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i){
		for (int j = i + 1; j < n; ++j) {
			if (a[i] == a[j]) {
				p++;
				if (p == k) { b.push_back(a[i]); break; }
			}
		}
		p = 1;
		}
	for (int i = 0; i < b.size(); ++i)
		for (int j = i + 1; j < b.size(); ++j)
			if (b[i] == b[j]) b.pop_back();
	int l = b.size();
	cout << b.size() << endl;
	for (auto i : b)cout << i << ' ';
	return 0;
}