#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> ids(n);
  vector<bool> en_pantalla(1000000001);
  vector<int> pantalla;
  int indice_inicial = 0;
  for (int i = 0; i < n; i++) {
    cin >> ids[i];
  }
  for (int i = 0; i < n; ++i) {
    if (!en_pantalla[ids[i]]) {
      if (pantalla.size() - indice_inicial < k) {
        pantalla.push_back(ids[i]);
        en_pantalla[ids[i]] = true;
      } else {
        pantalla.push_back(ids[i]);
        en_pantalla[pantalla[indice_inicial]] = false;
        indice_inicial++;
        en_pantalla[ids[i]] = true;
      }
    }
  }
  cout << pantalla.size() - indice_inicial << endl;
  for (int i = pantalla.size() - 1; i >= indice_inicial; i--) {
    cout << pantalla[i] << " ";
  }
  cout << endl;
  return 0;
}
