#include <bits/stdc++.h>
using namespace std;
int main() {
  set<int> m;
  list<int> v;
  int n, k;
  cin >> n >> k;
  for (int i = 0, t; i < n; ++i) {
    cin >> t;
    if (m.find(t) != m.end()) {
      continue;
    } else if (v.size() < k) {
      v.push_back(t);
      m.insert(t);
      continue;
    } else {
      m.erase(*v.begin());
      v.pop_front();
      v.push_back(t);
      m.insert(t);
    }
  }
  cout << v.size() << endl;
  v.reverse();
  for (auto it = v.begin(); it != v.end(); ++it) {
    cout << *it << " ";
  }
  cout << endl;
}
