#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  deque<int> q;
  int count = 0;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (m.find(a[i]) != m.end()) {
      if (count - m[a[i]] > k) {
        if (q.size() < k) {
          q.push_front(a[i]);
          m[a[i]] = count;
          count++;
        } else {
          q.pop_back();
          q.push_front(a[i]);
          m[a[i]] = count;
          count++;
        }
      }
    } else {
      if (q.size() < k) {
        q.push_front(a[i]);
        m[a[i]] = count;
        count++;
      } else {
        q.pop_back();
        q.push_front(a[i]);
        m[a[i]] = count;
        count++;
      }
    }
  }
  cout << q.size() << "\n";
  for (int i = 0; i < q.size(); i++) cout << q[i] << " ";
  return 0;
}
