#include <bits/stdc++.h>
using namespace std;
long long i, j, t, s = 0, c = 0, n, m, k = 0, k1 = 0, k2 = 0, k3 = 0, k4 = 0,
                   k5 = 0;
string s1;
signed main() {
  cin >> n >> k;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  vector<long long> v1;
  i = 0;
  map<long long, long long> m1;
  set<long long> s2;
  queue<long long> q;
  for (long long i = 0; i < n; i++) {
    if (s2.find(v[i]) == s2.end()) {
      if (q.size() >= k) {
        k2 = q.front();
        q.pop();
        s2.erase(k2);
      }
      q.push(v[i]);
      s2.insert(v[i]);
    }
  }
  vector<long long> v2;
  while (!q.empty()) {
    v2.push_back(q.front());
    q.pop();
  }
  reverse(v2.begin(), v2.end());
  cout << ((long long)(v2).size()) << "\n";
  for (long long i = 0; i < ((long long)(v2).size()); i++) cout << v2[i] << " ";
}
