#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2e5 + 7;
const int inf = 1e9 + 7;
int n, k;
queue<int> q;
map<int, int> mp;
int ans[Maxn];
int main() {
  scanf("%d%d", &n, &k);
  int num;
  for (int i = 0; i < n; i++) {
    scanf("%d", &num);
    if (mp[num] == 0) {
      mp[num]++;
      if (q.size() < k) {
        q.push(num);
      } else {
        int fr = q.front();
        mp[fr]--;
        q.pop();
        q.push(num);
      }
    }
  }
  printf("%d\n", q.size());
  int cnt = 0;
  while (!q.empty()) {
    ans[cnt++] = q.front();
    q.pop();
  }
  for (int i = cnt - 1; i >= 0; i--) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
