#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  solve();
  return 0;
}
void solve() {
  int i, n, k, t, tt;
  cin >> n >> k;
  set<int> a;
  queue<int> q;
  for (i = 0; i < n; i++) {
    cin >> t;
    if (a.find(t) == a.end()) {
      if (q.size() == k) {
        tt = q.front();
        q.pop();
        a.erase(tt);
      }
      q.push(t);
      a.insert(t);
    }
  }
  vector<int> b;
  while (!q.empty()) {
    b.push_back(q.front());
    q.pop();
  }
  cout << b.size() << "\n";
  for (i = b.size() - 1; i > -1; i--) {
    cout << b[i] << " ";
  }
}
