#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, a;
  cin >> n >> k;
  list<int> lst;
  map<int, bool> vis;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (lst.size() < k) {
      if (vis.find(a) == vis.end()) {
        lst.push_front(a);
        vis[a] = true;
      }
      continue;
    }
    if (vis.find(a) == vis.end() || vis[a] == false) {
      vis[a] = true;
      vis[lst.back()] = false;
      lst.pop_back();
      lst.push_front(a);
    }
  }
  cout << lst.size() << endl;
  for (auto it = lst.begin(); it != lst.end(); it++) cout << (*it) << " ";
  cout << endl;
  return 0;
}
