#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int x[200008] = {0};
  map<int, bool> f;
  int l = 0, r = 0;
  while (n--) {
    int id;
    scanf("%d", &id);
    if (!f[id]) {
      f[id] = true;
      x[++r] = id;
      if (r - l > k) f[x[++l]] = false;
    }
  }
  printf("%d\n", r - l);
  while (r > l) {
    if (r == l + 1)
      printf("%d", x[r--]);
    else
      printf("%d ", x[r--]);
  }
}
