#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  deque<int> dq;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (mp[x] == 0) {
      if (dq.size() >= k) {
        int gg = dq.back();
        dq.pop_back();
        mp[gg] = 0;
        mp[x]++;
        dq.push_front(x);
      } else {
        mp[x]++;
        dq.push_front(x);
      }
    }
  }
  cout << dq.size() << endl;
  for (auto i : dq) {
    cout << i << endl;
  }
}
