#include <bits/stdc++.h>
#pragma GCC optimization("O3")
const long long M = 1000000;
using namespace std;
signed main() {
  long long n, k;
  cin >> n >> k;
  long long arr[n];
  map<long long, long long> mp;
  queue<long long> q;
  vector<long long> ans;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    mp[arr[i]] = 0;
  }
  for (long long i = 0; i < n; i++) {
    if (q.size() < k) {
      if (!mp[arr[i]]) {
        mp[arr[i]] = 1;
        q.push(arr[i]);
      }
    } else if (q.size() >= k) {
      if (!mp[arr[i]]) {
        q.push(arr[i]);
        mp[arr[i]] = 1;
        mp[q.front()] = 0;
        q.pop();
      }
    }
  }
  cout << q.size() << "\n";
  while (!q.empty()) {
    ans.push_back(q.front());
    q.pop();
  }
  for (long long i = ans.size() - 1; i >= 0; i--) cout << ans[i] << " ";
  return 0;
}
