#include <bits/stdc++.h>
using namespace std;
int main() {
  deque<int> q;
  int s, n;
  cin >> s >> n;
  map<int, int> m;
  for (int i = 0; i < s; i++) {
    int h;
    cin >> h;
    if (m[h] == 0) {
      m[h]++;
      if (q.size() == n) {
        int k = q.back();
        m[k] = 0;
        q.pop_back();
        q.push_front(h);
      } else
        q.push_front(h);
    }
  }
  cout << q.size() << endl;
  for (int i = 0; i < q.size(); i++) cout << q[i] << " ";
  return 0;
}
