#include <bits/stdc++.h>
using namespace std;
long long int m = 1000000000 + 7;
int main() {
  int i, j, k, n, l, c, x = 0;
  cin >> n >> k;
  queue<int> a;
  set<int> b;
  for (i = 0; i < n; i++) {
    cin >> l;
    if (i == 0) {
      a.push(l);
      b.insert(l);
    } else {
      auto it = b.find(l);
      if (it == b.end()) {
        if (a.size() == k) {
          c = a.front();
          a.pop();
          b.erase(c);
          a.push(l);
          b.insert(l);
        } else {
          a.push(l);
          b.insert(l);
        }
      }
    }
  }
  cout << a.size() << endl;
  c = 0;
  stack<int> d;
  while (a.size() != 0) {
    x = a.front();
    a.pop();
    d.push(x);
    c++;
  }
  while (d.size() != 0) {
    cout << d.top() << " ";
    d.pop();
  }
}
