#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int arr[200007];
  map<int, bool> vis;
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    if (vis[arr[i]]) continue;
    vis[arr[i]] = true;
    if (q.size() == k) {
      vis[q.front()] = false;
      q.pop();
    }
    q.push(arr[i]);
  }
  vector<int> v;
  while (!q.empty()) {
    v.push_back(q.front());
    q.pop();
  }
  cout << (int)v.size() << endl;
  for (int i = (int)v.size() - 1; i >= 0; i--) {
    cout << v[i] << ' ';
  }
  cout << endl;
  return 0;
}
