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