#include <bits/stdc++.h>
using namespace std;
void PLAY() {
  cout << fixed << setprecision(10);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  deque<long long> x;
  map<long long, long long> h;
  for (int i = 0; i < n; i++) {
    long long f;
    cin >> f;
    if (h[f] == 0) {
      h[f] = 1;
      x.push_back(f);
      long long l = x.size();
      if (l == k + 1) {
        h[x.front()] = 0;
        x.pop_front();
      }
    }
  }
  cout << x.size() << endl;
  reverse(x.begin(), x.end());
  long long l = x.size();
  for (auto it : x) {
    cout << it << " ";
  }
  cout << endl;
  return 0;
}
