#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  deque<long long int> dq;
  map<long long int, bool> window;
  for (int i = 0; i < n; i++) {
    long long int feed;
    cin >> feed;
    if (dq.size() <= k) {
      if (window[feed])
        continue;
      else {
        dq.push_front(feed);
        window[feed] = true;
      }
    }
    if (dq.size() > k) {
      window.erase(dq[k]);
      dq.pop_back();
    }
  }
  cout << dq.size() << endl;
  for (auto x : dq) cout << x << " ";
  return 0;
}
