#include <bits/stdc++.h>
using namespace std;
int n, k;
map<int, bool> m;
deque<int> coada;
int main() {
  int x;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> x;
    if (!m[x]) {
      m[x] = 1;
      coada.push_front(x);
      if (coada.size() == k + 1) {
        m[coada.back()] = 0;
        coada.pop_back();
      }
    }
  }
  cout << coada.size() << '\n';
  while (!coada.empty()) {
    cout << coada.front() << " ";
    coada.pop_front();
  }
  return 0;
}
