#include <bits/stdc++.h>
using namespace std;
int main() {
  queue<int> id;
  set<int> val;
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int ids;
    cin >> ids;
    if (!val.count(ids)) {
      if (id.size() >= k) {
        int cur = id.front();
        id.pop();
        val.erase(cur);
      }
      id.push(ids);
      val.insert(ids);
    }
  }
  vector<int> v;
  while (!id.empty()) {
    v.push_back(id.front());
    id.pop();
  }
  reverse(v.begin(), v.end());
  cout << v.size() << "\n";
  for (auto i : v) cout << i << " ";
  cout << "\n";
}
