#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 50;
vector<int> a(maxn);
int main() {
  int n, k;
  deque<int> q;
  map<int, bool> notinuse;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    notinuse[a[i]] = true;
  }
  for (int i = 0; i < n; i++) {
    if (q.size() <= k) {
      if (!notinuse[a[i]])
        continue;
      else {
        q.push_front(a[i]);
        notinuse[a[i]] = false;
      }
    }
    if (q.size() > k) {
      notinuse[q.back()] = true;
      q.pop_back();
    }
  }
  cout << q.size() << endl;
  while (q.size()) {
    cout << q.front() << " ";
    q.pop_front();
  }
  return 0;
}
