#include <bits/stdc++.h>
using namespace std;
void solve(istream& in, ostream& out) {
  int n, k;
  in >> n >> k;
  deque<int> q;
  set<int> active;
  for (int i = 0; i < n; ++i) {
    int id;
    in >> id;
    if (active.count(id)) continue;
    q.emplace_front(id);
    active.emplace(id);
    if (q.size() > k) {
      active.erase(q.back());
      q.pop_back();
    }
  }
  out << q.size() << endl;
  while (!q.empty()) {
    out << q.front() << " ";
    q.pop_front();
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solve(in, out);
}
