#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, id;
  cin >> n >> k;
  map<long long, bool> mappeopele;
  queue<long long> q;
  stack<long long> s;
  for (int i = 0; i < n; i++) {
    cin >> id;
    if (mappeopele[id])
      continue;
    else {
      if (q.size() < k) {
        q.push(id);
        mappeopele[id] = true;
      } else {
        mappeopele[q.front()] = false;
        q.pop();
        q.push(id);
        mappeopele[id] = true;
      }
    }
  }
  cout << q.size() << endl;
  while (!q.empty()) {
    s.push(q.front());
    q.pop();
  }
  while (!s.empty()) {
    cout << s.top() << " ";
    s.pop();
  }
  return 0;
}
