#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp;
int main() {
  long long n, k;
  cin >> n >> k;
  queue<long long> q;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (mp[x] == 0) {
      mp[x] = 1;
      q.push(x);
    }
    if (q.size() > k) {
      long long fc = q.front();
      q.pop();
      mp[fc] = 0;
    }
  }
  vector<long long> v;
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    v.push_back(x);
  }
  reverse(v.begin(), v.end());
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  return 0;
}
