#include <iostream>

using namespace std;
int main()
{
	const long max_n = 1000000;
	long* a = new long[max_n * 2 + 1];
	long* saved = new long[max_n];
	long n, k;
	long sum = 0;
	long c = 0;

	cin >> n >> k;
	for (long i = 0; i < n; i++) {
		a[i] = 0;
		a[n + i] = 0;
		saved[i] = 0;
	}
	for (long i = 0; i < n; i++) {
		long t;
		cin >> t;
		a[n + t]++;
		if (a[n + t] == k) {
			sum++;
			saved[c] = t;
			c++;
		}
	}
	cout << sum << endl;
	for (long i = 0; i < c; i++) {
		cout << saved[i] << " ";
	}
	cout << endl;
}