#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  unordered_map<long long int, int> m;
  int b[n];
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  deque<int> q;
  for (int i = 0; i < n; i++) {
    if (m[b[i]] == 1) {
    } else {
      if ((int)q.size() == k) {
        int l = q.front();
        m[l] = 0;
        q.pop_front();
      }
      q.push_back(b[i]);
      m[b[i]] = 1;
    }
  }
  cout << q.size() << "\n";
  while (q.empty() == false) {
    cout << q.back() << " ";
    q.pop_back();
  }
  cout << "\n";
}
