#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
using namespace std;
int t;
int q[maxn];
map<int, int> m;
int main() {
  int n, k;
  cin >> n >> k;
  int f = 0, r = 0;
  for (int i = 0; i < n; i++) {
    cin >> t;
    if (m[t] == 0) {
      q[f++] = t;
      m[t] = 1;
    }
    if ((f - r) > k) {
      m[q[r]] = 0;
      r++;
    }
  }
  cout << f - r << endl;
  for (int i = f - 1; i >= r; i--) {
    cout << q[i] << ' ';
  }
  return 0;
}
