#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  deque<int> q;
  set<int> s;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (!s.count(a[i])) {
      if (q.size() < k) {
        q.push_back(a[i]);
        s.insert(a[i]);
      } else {
        s.erase(q.front());
        q.pop_front();
        s.insert(a[i]);
        q.push_back(a[i]);
      }
    }
  }
  cout << q.size() << endl;
  while (!q.empty()) {
    cout << q.back() << " ";
    q.pop_back();
  }
  cout << endl;
}
