#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  map<int, int> m;
  set<int> s;
  queue<int> q;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (s.find(x) == s.end()) {
      if (q.size() == k) {
        m[q.front()]--;
        if (m[q.front()] == 0) s.erase(q.front());
        q.pop();
      }
      q.push(x);
      s.insert(x);
      m[x] = 1;
    }
  }
  cout << q.size() << "\n";
  stack<int> st;
  while (!q.empty()) {
    st.push(q.front());
    q.pop();
  }
  while (!st.empty()) {
    cout << st.top() << " ";
    st.pop();
  }
  cout << "\n";
  return 0;
}
