#include <bits/stdc++.h>
using namespace std;
int main() {
  int samples, len, temp, sz;
  cin >> samples >> len;
  deque<int> q;
  set<int> s;
  sz = s.size();
  for (; samples--;) {
    cin >> temp;
    s.insert(temp);
    if (s.size() > sz) {
      q.push_front(temp);
      if (q.size() > len) {
        s.erase(q[q.size() - 1]);
        q.pop_back();
      }
    }
    sz = s.size();
  }
  printf("%d\n", q.size());
  for (auto x : q) printf("%d ", x);
  return 0;
}
