#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, i, k, j, l, t;
  cin >> n >> k;
  long a[n];
  deque<long> q;
  set<long> s;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    if (s.count(a[i]) == 1)
      continue;
    else if (s.size() < k)
      s.insert(a[i]);
    else {
      s.erase(q.back());
      s.insert(a[i]);
    }
    if (q.size() < k) {
      q.push_front(a[i]);
    } else {
      q.pop_back();
      q.push_front(a[i]);
    }
  }
  cout << q.size() << endl;
  for (i = 0; i < q.size(); i++) cout << q[i] << " ";
}
