#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
deque<int> q;
int main() {
  int n, k, x, temp;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (!mp[x]) {
      q.push_front(x);
      mp[x] = 1;
    }
    if (q.size() > k) {
      temp = q.back();
      q.pop_back();
      mp[temp] = 0;
    }
  }
  printf("%d\n", q.size());
  while (!q.empty()) {
    printf("%d ", q.front());
    q.pop_front();
  }
  return 0;
}
