#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k, i, f;
  cin >> n >> k;
  int a[n];
  set<int> s;
  deque<int> d;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (s.find(a[i]) != s.end()) continue;
    if (d.size() >= k) s.erase(d[k - 1]);
    s.insert(a[i]);
    d.push_front(a[i]);
  }
  if (d.size() > k)
    f = k;
  else
    f = d.size();
  cout << f << endl;
  for (i = 0; i < f; i++) cout << d[i] << " ";
}
