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