#include <cstdio>
#include <algorithm>
#include <vector>

long long n, k, c, A[1000010];
std::vector<long long> V;

int main() {

	scanf("%lld%lld", &n, &k);
	A[0] = 1000000000;
	for (long long i = 1; i <= n; i++) {
		scanf("%lld", &A[i]);
	}
	A[n + 1] = 1000000000;
	std::sort(A + 1, A + n + 1);
	for (long long i = 1; i <= n + 1; i++) {
		if ((A[i] != A[i - 1])) {
			if (c >= k) {
				V.push_back(A[i - 1]);
			}
			c = 0;
		}
		c++;
	}
	printf("%lld\n", (long long)V.size());
	for (long long i = 0; i < (long long)V.size(); i++) {
		printf("%lld ", V[i]);
	}
	printf("\n");
	return 0;
}