#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  queue<int> q;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    if (q.size() < k) {
      if (mp[tmp] == 0) {
        mp[tmp] = 1;
        q.push(tmp);
      }
    } else {
      if (mp[tmp] == 0) {
        mp[q.front()] = 0;
        q.pop();
        mp[tmp] = 1;
        q.push(tmp);
      }
    }
  }
  cout << q.size() << "\n";
  vector<int> ans;
  while (q.size() != 0) {
    ans.push_back(q.front());
    q.pop();
  }
  for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i] << " ";
}
