#include <bits/stdc++.h>
using namespace std;
long long quick_pow(long long a, long long b, long long mod) {
  long long x, y;
  x = 1;
  y = a;
  while (b != 0) {
    if (b & 1) x = x * y % mod;
    y = y * y % mod;
    b = b >> 1;
  }
  return x;
}
int main() {
  int n, k;
  cin >> n >> k;
  queue<int> q;
  map<int, bool> m;
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (m.count(x) && m[x] == 1)
      continue;
    else {
      if (q.size() == k) {
        m[q.front()] = 0;
        q.pop();
      }
      m[x] = 1;
      q.push(x);
    }
  }
  cout << q.size() << endl;
  while (q.size()) {
    ans.push_back(q.front());
    q.pop();
  }
  for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i] << " ";
  return 0;
}
