#include <bits/stdc++.h>
using namespace std;
int hg;
string gh = "here";
int main() {
  int n, k;
  cin >> n >> k;
  deque<int> d;
  map<int, bool> arr;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    if (arr[t] == 0) {
      d.push_front(t);
      arr[t] = 1;
      if (d.size() > k) {
        arr[d.at(k)] = 0;
        d.pop_back();
      }
    }
  }
  int s = d.size();
  cout << s << '\n';
  for (int i = 0; i < d.size(); i++) {
    cout << d.at(i) << ' ';
  }
  return 0;
}
