#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  long long int ara[n + 5];
  for (int i = 0; i < n; i++) cin >> ara[i];
  deque<int> dq;
  map<long long, int> track;
  for (int i = 0; i < n; i++) {
    if (dq.size() < k) {
      if (track[ara[i]] == 0) {
        track[ara[i]] = 1;
        dq.push_front(ara[i]);
      }
    } else {
      long long int backint = dq.back();
      if (track[ara[i]] == 0) {
        track[dq.back()] = 0;
        dq.pop_back();
        track[ara[i]] = 1;
        dq.push_front(ara[i]);
      }
    }
  }
  cout << dq.size() << endl;
  deque<int>::iterator it;
  for (it = dq.begin(); it != dq.end(); ++it) cout << *it << " ";
  cout << endl;
}
