#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  deque<int> d;
  set<int> iq;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    if (iq.find(tmp) == iq.end() && d.size() < k) {
      d.push_front(tmp);
      iq.insert(tmp);
    } else if (iq.find(tmp) == iq.end()) {
      iq.erase(iq.find(d.back()));
      d.pop_back();
      iq.insert(tmp);
      d.push_front(tmp);
    }
  }
  cout << d.size() << endl;
  for (auto x : d) cout << x << " ";
}
