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