#include <bits/stdc++.h>
using std::queue;
using std::set;
using std::vector;
int main() {
  int n, k, i, x;
  queue<int> q;
  set<int> st;
  std::cin >> n >> k;
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    if (st.count(x) == 0) {
      st.insert(x);
      q.push(x);
      if (st.size() > k) {
        st.erase(q.front());
        q.pop();
      }
    }
  }
  vector<int> solve;
  while (!q.empty()) {
    solve.push_back(q.front());
    q.pop();
  }
  std::reverse(solve.begin(), solve.end());
  printf("%d\n", solve.size());
  for (auto& r : solve) printf("%d ", r);
  return 0;
}
