#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, cant = 0, a, index = 0;
  cin >> n >> k;
  vector<long long> v;
  map<long long, long long> m;
  for (long long i = 0; i < n; ++i) {
    cin >> a;
    if (m[a] == 0) {
      if (cant < k) {
        v.push_back(a);
        cant++;
        m[a] = 1;
      } else {
        v.push_back(a);
        m[a] = 1;
        m[v[index]] = 0;
        index++;
      }
    }
  }
  cout << cant << endl;
  for (long long i = v.size() - 1; i >= index; i--) {
    cout << v[i] << " ";
  }
  cout << endl;
}
