#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, k;
  cin >> n >> k;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  deque<long long int> dq;
  dq.push_front(a[0]);
  unordered_map<long long int, long long int> mp;
  mp[a[0]]++;
  for (long long int i = 1; i < n; i++) {
    long long int x = a[i];
    if (mp[x] == 1) continue;
    dq.push_front(x);
    mp[x] = 1;
    if (dq.size() > k) {
      long long int pp = dq.back();
      dq.pop_back();
      mp[pp] = 0;
    }
  }
  cout << dq.size() << "\n";
  while (!dq.empty()) {
    cout << dq.front() << " ";
    dq.pop_front();
  }
}
