#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int arr[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  map<int, int> mp;
  deque<int> vec;
  int sz = 0;
  for (int i = 0; i < n; i++) {
    if (mp[arr[i]] == 0) {
      mp[arr[i]] = 1;
      if (sz == k) {
        mp[vec.back()] = 0;
        vec.pop_back();
        sz--;
      }
      vec.push_front(arr[i]);
      sz++;
    }
  }
  cout << sz << "\n";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    cout << *it << " ";
  }
}
