#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  deque<long> screen;
  long n, k;
  cin >> n >> k;
  map<long, long> onscreen;
  vector<long> ids;
  for (long i = 0; i < n; i++) {
    long p;
    cin >> p;
    ids.push_back(p);
  }
  for (long i = 0; i < n; i++) {
    onscreen[ids[i]] = 0;
  }
  long friends = onscreen.size();
  for (long i = 0; i < n; i++) {
    if (onscreen[ids[i]] == 0) {
      screen.push_back(ids[i]);
      onscreen[ids[i]] = 1;
      if (screen.size() > k) {
        onscreen[screen.front()] = 0;
        screen.pop_front();
      }
    }
  }
  n = min(friends, k);
  cout << n << endl;
  for (long i = 0; i < n; i++) {
    cout << (screen.back()) << " ";
    screen.pop_back();
  }
  return 0;
}
