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

using namespace std;

int main() {

	int n, k, x, br = 0;
	cin >> n >> k;

	vector<int> Pogodjene;
	vector<int> Zamena;

	for (int i = 0; i < n; i++) {		
		cin >> x;
		Pogodjene.push_back(x);
	}

	sort(Pogodjene.begin(), Pogodjene.end());
	x = Pogodjene[0];


	for (int i = 0; i < n; i++) {

		if (n == 1 && k==1) {
			cout << 1 << endl;
			cout << x;
			break;
		}

		if ((br >= k) && (x != Pogodjene[i])) {
			Zamena.push_back(x);
			x = Pogodjene[i];
			br = 1;
		}

		if ((br >= k) && (i == n - 1)) {
			Zamena.push_back(x);
		}

		if (Pogodjene[i] == x) {
			br++;
		}    		
		else {
			x = Pogodjene[i];
			br = 1;				
		}
	}

	cout << Zamena.size() << endl;

	for (int i = 0; i < Zamena.size(); i++) {
		cout << Zamena[i]<<" ";
	}

	return 0;
}