#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  deque<long long int> q;
  long long int id[n];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> id[i];
  }
  map<long long int, bool> mp;
  for (int i = 0; i < n; i++) {
    if (cnt == k) {
      break;
    }
    if (mp[id[i]] == true) continue;
    mp[id[i]] = true;
    cnt++;
    q.push_front(id[i]);
  }
  if (q.size() < k) {
    cout << q.size() << endl;
    for (long long itr : q) {
      cout << itr << " ";
    }
    return 0;
  } else {
    for (int i = cnt; i < n; i++) {
      if (mp[id[i]]) continue;
      mp[id[i]] = true;
      q.push_front(id[i]);
      mp[q.back()] = false;
      q.pop_back();
    }
  }
  cout << q.size() << endl;
  for (long long itr : q) {
    cout << itr << " ";
  }
}
