#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
int q[maxn];
int main() {
  int k, n;
  cin >> n >> k;
  int h = 1, t = 0;
  map<int, int> m;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (m[x] == 1) continue;
    m[x] = 1;
    q[++t] = x;
    if (t - h >= k) {
      m[q[h]] = 0;
      h++;
    }
  }
  cout << t - h + 1 << endl;
  for (int i = t; i >= h; i--) cout << q[i] << " ";
  cout << endl;
  return 0;
}
