#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  deque<int> dq;
  map<int, int> freq;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (freq[x] == 0) {
      if ((int)dq.size() < k)
        dq.push_front(x);
      else {
        dq.push_front(x);
        freq[dq.back()] = 0;
        dq.pop_back();
      }
      freq[x] = 1;
    }
  }
  cout << (int)dq.size() << '\n';
  for (auto i : dq) cout << i << " ";
  cout << '\n';
  return 0;
}
