#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, id, i = 1, j = 1;
  cin >> n >> k;
  map<int, int> m;
  int arr[300000];
  while (n--) {
    scanf("%d", &id);
    if (j - i < k && !m.count(id)) {
      m[id] = 1;
      arr[j] = id;
      j++;
    } else if (j - i == k && !m.count(id)) {
      m[id] = 1;
      arr[j] = id;
      j++;
      m.erase(arr[i]);
      i++;
    }
  }
  printf("%d\n", j - i);
  for (int k = j - 1; k >= i; k--) printf("%d ", arr[k]);
  return 0;
}
