#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, id;
  deque<int> q;
  map<int, bool> m;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &id);
    if (!m[id]) {
      q.push_front(id);
      m[id] = true;
    }
    if (q.size() > k) {
      int temp = q.back();
      q.pop_back();
      m[temp] = false;
    }
  }
  printf("%d\n", (int)q.size());
  for (int i = 0; i < q.size(); i++)
    if (i < q.size() - 1)
      printf("%d ", q[i]);
    else
      printf("%d\n", q[i]);
  return 0;
}
