#include <bits/stdc++.h>
using namespace std;
map<int, bool> M;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T, K, c1;
  cin >> T >> K;
  deque<int> D;
  int N = T;
  while (T--) {
    cin >> c1;
    if (M.find(c1) != M.end() && M[c1] == true) {
      continue;
    } else if (D.size() < K) {
      D.push_front(c1);
      M[c1] = true;
    } else {
      M[D.back()] = false;
      D.pop_back();
      M[c1] = true;
      D.push_front(c1);
    }
  }
  cout << D.size() << '\n';
  while (!D.empty()) {
    cout << D.front() << " ";
    D.pop_front();
  }
  return 0;
}
