#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  map<int, int> m;
  deque<int> q;
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) {
    if (m.find(arr[i]) == m.end()) {
      if (q.size() < k) {
        q.push_back(arr[i]);
        m[arr[i]]++;
      } else if (q.size() == k) {
        int temp = q.front();
        q.pop_front();
        m.erase(temp);
        q.push_back(arr[i]);
        m[arr[i]]++;
      }
    }
  }
  int p = q.size();
  cout << p << endl;
  while (!q.empty()) {
    cout << q.back() << " ";
    q.pop_back();
  }
  return 0;
}
