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