#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
deque<long long> de;
map<long long, long long> mp;
int main() {
  long long n, k;
  scanf("%lld%lld", &n, &k);
  long long x;
  long long len = 0;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &x);
    if (mp[x] == 0) {
      if (len == k) {
        mp[de.back()]--;
        de.pop_back();
        mp[x]++;
        de.push_front(x);
      } else {
        len++;
        de.push_front(x);
        mp[x]++;
      }
    }
  }
  printf("%lld\n", len);
  while (!de.empty()) {
    len--;
    printf("%lld", de.front());
    de.pop_front();
    if (len == 0)
      printf("\n");
    else
      printf(" ");
  }
  return 0;
}
