#include <iostream>
using namespace std;
int main() {
	int n, k, x[1001],m[1001], br = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (x[i] == x[j]) br++;
            if (x[i] == x[j+1]) br=br;
		}
	}
	if (br >= k) {
		cout << br << endl;
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if ((x[i] == x[j]) and (br >= k)) {
				m[i] = x[i];
				cout << m[i] << " ";
			}
			if (m[i] == m[j + 1]) {
				cout <<"";
			}
		}
	}
	return 0;
}