#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
const int N = 2000005;
int T, n, a[N], s[N], top, k, x, top1;
inline void fr(int &num) {
  num = 0;
  char c = getchar();
  int p = 1;
  while (c < '0' || c > '9') c == '-' ? p = -1, c = getchar() : c = getchar();
  while (c >= '0' && c <= '9') num = num * 10 + c - '0', c = getchar();
  num *= p;
}
int main() {
  fr(n), fr(k);
  top1 = 1;
  while (n--) {
    fr(x);
    if (mp[x]) continue;
    mp[x] = 1, s[++top] = x;
    if (top > k) mp[s[top - k]] = 0, ++top1;
  }
  printf("%d\n", top - top1 + 1);
  while (top >= top1) printf("%d ", s[top--]);
  return 0;
}
