#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  set<int> s;
  deque<int> dq;
  int i = 0;
  int total = 0;
  while (i < n) {
    if ((dq.empty() || s.empty() || total < m) && s.find(arr[i]) == s.end()) {
      dq.push_front(arr[i]);
      s.insert(arr[i]);
      total++;
    } else if (s.find(arr[i]) == s.end()) {
      int val = dq.back();
      set<int>::iterator itr = s.find(val);
      s.erase(itr);
      dq.pop_back();
      dq.push_front(arr[i]);
      s.insert(arr[i]);
    }
    i++;
  }
  vector<int> res;
  while (!dq.empty()) {
    res.push_back(dq.front());
    dq.pop_front();
  }
  int l = res.size();
  cout << l << endl;
  for (int i = 0; i < l; i++) {
    cout << res[i] << " ";
  }
}
