#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, x;
  cin >> n >> k;
  queue<int> s;
  map<int, int> mymap;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (!mymap[x]) {
      if (s.size() == k) {
        mymap[s.front()] = 0;
        s.pop();
      }
      mymap[x] = 1;
      s.push(x);
    }
  }
  k = s.size();
  stack<int> q;
  cout << k << endl;
  while (!s.empty()) {
    q.push(s.front());
    s.pop();
  }
  while (!q.empty()) {
    cout << q.top() << " ";
    q.pop();
  }
  return 0;
}
