#include <bits/stdc++.h>
using namespace std;
int main() {
  set<long> convos;
  deque<long> messages;
  long n, k, f;
  cin >> n >> k;
  for (long i = 0; i < n; ++i) {
    cin >> f;
    if (convos.find(f) != convos.end()) {
      continue;
    } else {
      if ((long)messages.size() == k) {
        long last = messages.back();
        messages.pop_back();
        convos.erase(last);
      }
      messages.push_front(f);
      convos.insert(f);
    }
  }
  cout << messages.size() << "\n";
  for (auto it = messages.begin(); it != messages.end(); ++it)
    cout << *it << " ";
  cout << endl;
}
