#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> v(n, 0);
  for (long long int i = 0; i < n; i++) cin >> v[i];
  queue<long long int> q;
  unordered_set<long long int> s;
  for (long long int i = 0; i < n; i++) {
    if (q.size() < k) {
      if (s.count(v[i]) == 0) {
        s.insert(v[i]);
        q.push(v[i]);
      }
    } else {
      if (s.count(v[i]) == 0) {
        long long int topo = q.front();
        s.erase(topo);
        s.insert(v[i]);
        q.push(v[i]);
        q.pop();
      }
    }
  }
  cout << q.size() << endl;
  stack<long long int> st;
  while (!q.empty()) {
    st.push(q.front());
    q.pop();
  }
  while (!st.empty()) {
    cout << st.top() << " ";
    st.pop();
  }
  return 0;
}
