#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int arr[n];
  map<long long int, bool> mp;
  deque<long long int> dq;
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
    mp[arr[i]] = false;
  }
  for (long long int i = 0; i < n; i++) {
    if (!mp[arr[i]]) {
      mp[arr[i]] = true;
      if (dq.size() == k) {
        mp[dq.back()] = false;
        dq.pop_back();
      }
      dq.push_front(arr[i]);
    }
  }
  cout << dq.size() << endl;
  for (auto x : dq) {
    cout << x << " ";
  }
  cout << endl;
}
