#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> mp;
deque<long long int> dq;
int main() {
  long long int n, k, x;
  cin >> n >> k;
  for (long long int i = 0; i < n; i++) {
    cin >> x;
    if (mp[x] == 0) {
      if (dq.size() < k) {
        dq.push_back(x);
      } else {
        mp[dq.front()] = 0;
        dq.pop_front();
        dq.push_back(x);
      }
    }
    mp[x] = 1;
  }
  cout << dq.size() << endl;
  for (long long int i = dq.size() - 1; 0 <= i; i--) {
    cout << dq[i];
    if (i != 0) {
      cout << " ";
    }
  }
  cout << endl;
}
