#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, pos_for_del = 0;
  cin >> n >> k;
  set<int> last_k;
  vector<int> input;
  list<int> last_list;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (last_k.find(x) == last_k.end()) {
      input.push_back(x);
      if (last_k.size() == k) {
        last_k.erase(input[pos_for_del]);
        last_k.insert(x);
        pos_for_del++;
        last_list.pop_front();
        last_list.push_back(x);
      } else {
        last_list.push_back(x);
        last_k.insert(x);
      }
    }
  }
  cout << last_k.size() << endl;
  for (auto it = last_list.rbegin(); it != last_list.rend(); it++) {
    cout << *it << " ";
  }
  return 0;
}
