#include <bits/stdc++.h>
using namespace std;
template <typename T>
void trace(T a) {
  cout << a << '\n';
}
template <typename T, typename... Args>
void trace(T a, Args... args) {
  cout << a << ' ';
  trace(args...);
}
int a[100010];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  map<int, int> vis;
  queue<int> q;
  for (int i = 0; i < n; ++i) {
    if (vis[a[i]]) continue;
    if ((int)q.size() == k) {
      vis[q.front()] = 0;
      q.pop();
    }
    vis[a[i]] = 1;
    q.push(a[i]);
  }
  vector<int> foo;
  n = q.size();
  while (!q.empty()) {
    foo.push_back(q.front());
    q.pop();
  }
  reverse(foo.begin(), foo.end());
  trace(n);
  for (int i = 0; i < n; ++i) {
    cout << foo[i] << " \n"[i + 1 == (int)n];
  }
  return 0;
}
