#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  map<int, int> m;
  queue<int> q;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    if (m[temp] == 0) {
      if (q.size() == k) {
        m[q.front()]--;
        q.pop();
        q.push(temp);
        m[temp]++;
      } else {
        q.push(temp);
        m[temp]++;
      }
    }
  }
  cout << q.size() << endl;
  vector<int> v;
  while (!q.empty()) {
    v.push_back(q.front());
    q.pop();
  }
  reverse(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
}
