#include <bits/stdc++.h>
using namespace std;
void reverseQueue(queue<long long int>& q) {
  if (q.empty()) return;
  long long int data = q.front();
  q.pop();
  reverseQueue(q);
  q.push(data);
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  vector<long long int> friends;
  queue<long long int> q;
  map<long long int, int> check;
  for (int i = 0, temp; i < n; i++) {
    cin >> temp;
    friends.emplace_back(temp);
    if (i < k) {
      if (check.find(friends[i]) == check.end() || check[friends[i]] == 0) {
        q.push(temp);
        check[temp] = 1;
      }
    }
  }
  for (int i = k; i < n; i++) {
    if (check.find(friends[i]) == check.end() || check[friends[i]] == 0) {
      if (q.size() == k) {
        check[q.front()] = 0;
        q.pop();
      }
      q.push(friends[i]);
      check[friends[i]] = 1;
    }
  }
  reverseQueue(q);
  cout << q.size() << endl;
  while (!q.empty()) {
    cout << q.front() << " ";
    q.pop();
  }
  cout << endl;
  return 0;
}
