#include <bits/stdc++.h>
using namespace std;
int n, k, ans[200005], total = 0;
queue<int> q;
set<int> s;
int main() {
  int i, x;
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> x;
    if (s.count(x) == 0) {
      s.insert(x);
      q.push(x);
      if (q.size() > k) {
        s.erase(q.front());
        q.pop();
      }
    }
  }
  cout << q.size() << endl;
  while (q.size()) {
    ans[++total] = q.front();
    q.pop();
  }
  for (i = total; i >= 1; i--) cout << ans[i] << ' ';
  return 0;
}
