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

using namespace std;

vector<int>polja;
vector<int>R;

int zameniPolja(int n, int k) {
	int a = 1, broj = 0;
	for (int i = 1; i < n; i++) {
		if (polja[i] == polja[i - 1]) 
			a++;		
		else {
			if (a >= k) {
				R.push_back(polja[i - 1]);
				broj++;
			}
			a = 1;
		}
	}
	if (a >= k) {
		R.push_back(polja[n - 2]);
		broj++;
	}
	return broj;
}

int main()
{
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		polja.push_back(x);
	}		
	sort(polja.begin(), polja.begin() + n);
	
	cout << zameniPolja(n, k) << endl;
	for (int i = 0; i < zameniPolja(n, k); i++)
		cout << R[i] << " ";
}