#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
map<int, bool> cur;
int ans[maxn];
int main() {
  queue<int> q;
  int n, k;
  scanf("%d%d", &n, &k);
  int a;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    if (cur[a] == 0) {
      q.push(a);
      if (q.size() > k) {
        int t = q.front();
        cur[t] = 0;
        q.pop();
      }
      cur[a] = 1;
    }
  }
  int l = q.size();
  for (int i = 1; i <= l; i++) {
    ans[l - i + 1] = q.front();
    q.pop();
  }
  printf("%d\n", l);
  for (int i = 1; i <= l; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
