#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n = 0, k = 0;
  long long a = 0, b = 0, c = 0;
  cin >> n >> k;
  deque<int> arr;
  set<int> tf;
  while (n--) {
    cin >> a;
    if (tf.find(a) != tf.end()) continue;
    if (arr.size() == k) {
      tf.erase(arr.back());
      arr.pop_back();
    }
    arr.push_front(a);
    tf.insert(a);
  }
  cout << arr.size() << ("\n");
  cout << arr.front();
  arr.pop_front();
  while (!arr.empty()) {
    cout << " " << arr.front();
    arr.pop_front();
  }
  cout << ("\n");
  return 0;
}
