#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, t = 0;
  cin >> n >> k;
  int a[n];
  list<int> l;
  map<int, int> mp;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]] = 0;
  }
  for (long long int i = 0; i < n; i++) {
    if (mp[a[i]] != 1) {
      l.push_front(a[i]);
      mp[a[i]] = 1;
    }
    if (l.size() > k) {
      auto it = l.end();
      it--;
      mp[*it] = 0;
      l.pop_back();
    }
  }
  cout << l.size() << endl;
  for (auto it = l.begin(); it != l.end(); it++) {
    cout << *it << " ";
  }
  cout << endl;
}
