#include <bits/stdc++.h>
using namespace std;
ifstream fin("in");
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> f(n);
  for (int i = 0; i < n; i++) {
    cin >> f[i];
  }
  deque<int> q;
  set<int> s;
  for (int i = 0; i < n; i++) {
    if (s.find(f[i]) == s.end()) {
      s.insert(f[i]);
      q.push_front(f[i]);
      if (q.size() > k) {
        s.erase(q.back());
        q.pop_back();
      }
    }
  }
  cout << q.size() << endl;
  for (auto v : q) {
    cout << v << " ";
  }
  cout << endl;
  return 0;
}
