#include <iostream>
#include <vector>


using namespace std;

int main()
{
	vector <long> ulaz; // long ulaz[100000];
	vector <long> izlaz; // long izlaz[100000];
	long n, k, i, j, m, s, t, p;
	t = 0;
	s = 0;
	p = 0;

	cin >> n >> k;
	ulaz.resize(n+1);

	for (i = 1; i <= n; i++)
	{
		cin >> ulaz[i];
	}

	for (i = 1; i <= n; i++)
	{
		t = 1;
		if(ulaz[i] != 9999999)
			for (j = i+1; j <= n; j++)
			{
				if (ulaz[i] == ulaz[j])
					t++;
				if (t == k) {
					izlaz.push_back(ulaz[i]);
					p++;

					j = n;
					for (m = i + 1; m <= n; m++)
					{
						if (ulaz[m] == ulaz[i]) ulaz[m] = 9999999;
					}
					
				}

			}
	}

	cout << p << '\n';
	for (i = 0; i < p; i++)
		cout << izlaz[i] << ' ';

}