#include <bits/stdc++.h>
using namespace std;
set<long long int> sa;
queue<long long int> ho;
long long int a[200007], n, k, b[200007];
int main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (sa.find(a[i]) != sa.end())
      continue;
    else {
      if (ho.size() == k) {
        long long int lin;
        lin = ho.front();
        sa.erase(sa.find(lin));
        ho.pop();
        ho.push(a[i]);
        sa.insert(a[i]);
      } else {
        ho.push(a[i]);
        sa.insert(a[i]);
      }
    }
  }
  printf("%d\n", ho.size());
  int s = 0;
  while (!ho.empty()) {
    b[s++] = ho.front();
    ho.pop();
  }
  for (int i = s - 1; i >= 0; i--) {
    printf("%lld ", b[i]);
  }
  return 0;
}
