#include <bits/stdc++.h>
using namespace std;
queue<int> q;
map<int, bool> mp;
int n, k, x, a[200010];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (!mp[x]) {
      mp[x] = 1;
      q.push(x);
    }
    if (q.size() > k) {
      mp[q.front()] = 0;
      q.pop();
    }
  }
  int sz = q.size();
  printf("%d\n", sz);
  for (int i = 1; i <= sz; i++) {
    a[i] = q.front();
    q.pop();
  }
  for (int i = sz; i >= 1; i--) printf("%d%c", a[i], " \n"[i == 1]);
  return 0;
}
