#include <bits/stdc++.h>
using namespace std;
int main() {
  queue<int> q;
  vector<int> v;
  map<int, bool> m;
  int n, k, num;
  cin >> n;
  cin >> k;
  for (int i = 0; i < n; i++) {
    cin >> num;
    if (m[num] == false) {
      m[num] = true;
      if (q.size() < k) {
        q.push(num);
      } else {
        m[q.front()] = false;
        q.pop();
        q.push(num);
      }
    }
  }
  cout << q.size() << endl;
  for (int k = 0; !q.empty(); k++) {
    v.push_back(q.front());
    q.pop();
  }
  for (int ii = v.size() - 1; ii >= 0; ii--) {
    cout << v[ii] << endl;
  }
  return 0;
}
