#include <bits/stdc++.h>
using namespace std;
map<int, int> arr;
int main() {
  deque<int> visited;
  deque<int>::iterator it;
  int n, k, tmp;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    if (arr[tmp] == 0) {
      if (visited.size() == k) {
        it = visited.end();
        it--;
        arr[*it] = 0;
        visited.pop_back();
        visited.push_front(tmp);
        arr[tmp] = 1;
      } else if (visited.size() < k) {
        arr[tmp] = 1;
        visited.push_front(tmp);
      } else {
      }
    }
  }
  cout << visited.size() << endl;
  for (it = visited.begin(); it != visited.end(); it++) cout << *it << " ";
  return 0;
}
