#include <bits/stdc++.h>
using namespace std;
const int max_n = 2e5 + 5;
queue<int> q;
map<int, int> mp;
int ans[max_n];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (!mp.count(x) || mp[x] == 0) {
      mp[x] = 1;
      if (q.size() == k) {
        int _x = q.front();
        mp[_x] = 0;
        q.pop();
        q.push(x);
      } else
        q.push(x);
    }
  }
  int Q = q.size(), i = 0;
  cout << Q << endl;
  while (!q.empty()) {
    int _x = q.front();
    ans[i++] = _x;
    q.pop();
  }
  for (int i = Q - 1; i >= 0; i--) cout << ans[i] << " ";
  return 0;
}
