#include <bits/stdc++.h>
using namespace std;
int st[200010], n, k, l, r;
map<int, int> mp;
int main() {
  cin >> n >> k;
  l = 1;
  for (int i = 1, id; i <= n; ++i) {
    scanf("%d", &id);
    if (mp[id]) {
      continue;
    }
    if (r - l + 1 == k) {
      mp[st[l++]] = 0;
    }
    mp[st[++r] = id] = 1;
  }
  cout << r - l + 1 << endl;
  for (int i = r; i >= l; --i) {
    printf("%d ", st[i]);
  }
  return 0;
}
