#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, l = 0, r = 0;
  cin >> n >> k;
  deque<long long> v;
  set<long long> s;
  for (long long i = 0; i < n; i++) {
    int b;
    cin >> b;
    l = s.size();
    s.insert(b);
    r = s.size();
    if (l != r) {
      v.push_back(b);
    }
    if (s.size() > k) {
      long long h = v[0];
      s.erase(h);
      v.pop_front();
      v.resize(k);
    }
  }
  cout << s.size() << endl;
  reverse(v.begin(), v.end());
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  return 0;
}
