#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i, j, p, t = 0, l;
  queue<int> qu;
  map<int, int> mp;
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; i++) {
    scanf("%d", &p);
    if (mp[p] == 0) {
      if (t < k) {
        qu.push(p);
        mp[p]++;
        t++;
      } else {
        l = qu.front();
        qu.pop();
        mp[l]--;
        qu.push(p);
        mp[p]++;
      }
    }
  }
  vector<int> v;
  int sz;
  while (!qu.empty()) {
    l = qu.front();
    v.push_back(l);
    qu.pop();
  }
  sz = v.size();
  printf("%d\n", t);
  for (i = sz - 1; i >= 0; i--) printf("%d ", v[i]);
  v.clear();
  return 0;
}
