#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  long long a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  queue<int> q;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    if (m.find(a[i]) == m.end()) {
      if (q.size() == k) {
        m[a[i]] = 1;
        m.erase(q.front());
        q.pop();
        q.push(a[i]);
      } else {
        q.push(a[i]);
        m[a[i]] = 1;
      }
    }
  }
  stack<int> s;
  while (q.empty() != true) {
    s.push(q.front());
    q.pop();
  }
  cout << s.size() << endl;
  while (s.empty() != true) {
    cout << s.top() << " ";
    s.pop();
  }
  return 0;
}
