#include <bits/stdc++.h>
using namespace std;
int const N = 1e9 + 9;
bitset<N> a;
int main() {
  int n, k, j = 0;
  a.set();
  scanf("%d %d", &n, &k);
  deque<int> dq;
  while (n--) {
    int x;
    scanf("%d", &x);
    if (j < k) {
      if (a[x]) dq.push_front(x), j++, a[x] = 0;
    } else {
      if (a[x]) {
        a[dq.back()] = 1;
        a[x] = 0;
        dq.push_front(x);
        dq.pop_back();
      }
    }
  }
  printf("%d\n", (int)dq.size());
  for (auto i : dq) printf("%d ", i);
  puts("");
  return 0;
}
