#include <bits/stdc++.h>
using namespace std;
void print(queue<long int> qr) {
  int a;
  if (qr.size() == 1) {
    cout << qr.front() << " ";
    return;
  }
  a = qr.front();
  qr.pop();
  print(qr);
  cout << a << " ";
  return;
}
int main() {
  long int n, k, a;
  cin >> n >> k;
  queue<long int> screen;
  set<long int> scr;
  while (n--) {
    cin >> a;
    if (scr.count(a)) continue;
    if (screen.size() < k) {
      screen.push(a);
      scr.insert(a);
      continue;
    }
    scr.erase(screen.front());
    screen.pop();
    screen.push(a);
    scr.insert(a);
  }
  cout << screen.size() << endl;
  print(screen);
  return 0;
}
