#include <bits/stdc++.h>
using namespace std;
static const int N = (int)1e5 + 10;
int n, k;
map<int, int> in;
deque<int> q;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (in[x])
      continue;
    else {
      q.push_front(x);
      in[x] = 1;
      if (q.size() > k) {
        in[q.back()] = 0;
        q.pop_back();
      }
    }
  }
  printf("%d\n", q.size());
  for (auto x : q) printf("%d ", x);
  return 0;
}
