#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, x, p, q;
  cin >> n >> k;
  deque<int> d;
  set<int> s;
  for (int i = 0; i < n; i++) {
    cin >> x;
    set<int>::iterator it = s.find(x);
    if (it == s.end()) {
      s.insert(x);
      if (d.size() < k)
        d.push_front(x);
      else {
        d.push_front(x);
        int p = d.back();
        set<int>::iterator it1 = s.find(p);
        s.erase(it1);
        d.pop_back();
      }
    }
  }
  cout << d.size() << endl;
  while (!d.empty()) {
    int x = d.front();
    cout << x << " ";
    d.pop_front();
  }
}
