#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, a;
  cin >> n >> k;
  set<int> v;
  vector<int> r;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    if (v.find(a) != v.end()) continue;
    r.push_back(a);
    v.insert(a);
    if (r.size() > k) v.erase(r[r.size() - k - 1]);
  }
  int rs = r.size();
  int m = min(rs, k);
  cout << m << "\n";
  for (int i = 0; i < m; ++i) {
    cout << r[rs - i - 1] << " ";
  }
  return 0;
}
