#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, x;
  cin >> n >> k;
  map<long long, long long> mp;
  deque<long long> dq;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (mp[x]) continue;
    mp[x] = 1;
    if (dq.size() == k) {
      mp[dq.back()] = 0;
      dq.pop_back();
    }
    dq.push_front(x);
  }
  cout << dq.size() << endl;
  while (!dq.empty()) {
    cout << dq.front() << " ";
    dq.pop_front();
  }
  cout << endl;
}
