#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll i, j, t, n, k, a, r, x, y, x2, y2, dis, ans = 0;
  deque<ll> dq;
  map<ll, ll> mp;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a;
    if (!mp[a]) {
      if (dq.size() == k) {
        x = dq.back();
        dq.pop_back();
        mp[x] = 0;
      }
      dq.push_front(a);
      mp[a] = 1;
    }
  }
  cout << dq.size() << endl;
  for (auto it : dq) cout << it << " ";
  cout << endl;
  return 0;
}
