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