#include <bits/stdc++.h>
std ::map<int, bool> mp;
int n, k, id, list[500010], front, tail;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &id);
    if (mp[id]) continue;
    list[tail++] = id;
    mp[id] = 1;
    if (tail - front > k) mp[list[front++]] = 0;
  }
  printf("%d\n", tail - front);
  for (int i = tail - 1; i >= front; --i) printf("%d ", list[i]);
  return 0;
}
