#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int main() {
  long long int n, k, i;
  cin >> n >> k;
  long long int* a = new long long int[n];
  for (i = 0; i < n; i++) cin >> a[i];
  map<long long int, long long int> b;
  queue<long long int> v;
  for (i = 0; i < n; i++) {
    if (b[a[i]] == 1) {
    } else if (v.size() == k) {
      b[v.front()] = 0;
      v.pop();
      v.push(a[i]);
      b[a[i]] = 1;
    } else {
      v.push(a[i]);
      b[a[i]] = 1;
    }
  }
  cout << v.size() << endl;
  int l = v.size();
  int c[v.size()];
  for (long long int j = (v.size() - 1); j >= 0; j--) {
    c[j] = v.front();
    v.pop();
  }
  for (int i = 0; i < l; i++) {
    cout << c[i] << " ";
  }
}
