#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  deque<long long> v;
  vector<bool> visited((long long)1000000000, false);
  for (int i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    if (visited[x] == true) {
      continue;
    } else if (v.size() < k && visited[x] == false) {
      v.push_front(x);
      visited[x] = true;
    } else {
      visited[v[k - 1]] = false;
      v.push_front(x);
      visited[x] = true;
      v.pop_back();
    }
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size() - 1; ++i) {
    cout << v[i] << " ";
  }
  cout << v[v.size() - 1] << endl;
}
