#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long int n, k;
  cin >> n >> k;
  unsigned long long int arr[n];
  unsigned int max = 0;
  for (unsigned long long int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] > max) max = arr[i];
  }
  map<unsigned long long int, unsigned long long int> look;
  queue<unsigned long long int> q;
  for (unsigned long long int i = 0; i < n; i++) {
    if (q.size() < k) {
      if (look[arr[i]] == 0) {
        q.push(arr[i]);
        look[arr[i]] = 1;
      }
    } else {
      if (look[arr[i]] == 0) {
        unsigned long long int k = q.front();
        look[k] = 0;
        q.pop();
        q.push(arr[i]);
        look[arr[i]] = 1;
      }
    }
  }
  cout << q.size() << endl;
  unsigned long long int l = q.size();
  unsigned long long int m[l];
  for (unsigned long long int i = 0; i < l; i++) {
    m[l - i - 1] = q.front();
    q.pop();
  }
  for (unsigned long long int i = 0; i < l; i++) cout << m[i] << " ";
  return 0;
}
