#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  long long int id, remo;
  deque<long long int> dq;
  map<long long int, int> s;
  cin >> n >> k;
  while (n--) {
    cin >> id;
    if (dq.size() < k) {
      auto it = s.find(id);
      if (it == s.end()) {
        s.insert({id, 1});
        dq.push_back(id);
      }
    } else if (dq.size() == k) {
      auto it = s.find(id);
      if (it == s.end()) {
        s.insert({id, 1});
        remo = dq.front();
        s.erase(remo);
        dq.pop_front();
        dq.push_back(id);
      }
    }
  }
  cout << dq.size() << endl;
  while (!dq.empty()) {
    cout << dq.back();
    dq.pop_back();
    if (dq.size() != 0) cout << " ";
  }
  cout << endl;
}
