#include <bits/stdc++.h>
using namespace std;
void reverseQueue(queue<long>& Queue) {
  stack<long> Stack;
  while (!Queue.empty()) {
    Stack.push(Queue.front());
    Queue.pop();
  }
  while (!Stack.empty()) {
    Queue.push(Stack.top());
    Stack.pop();
  }
}
int main() {
  set<long> st;
  long n, k, a;
  cin >> n >> k;
  long t = 0;
  queue<long> q;
  while (n--) {
    cin >> a;
    auto it = st.find(a);
    if (it == st.end()) {
      if (t == k) {
        q.push(a);
        st.erase(q.front());
        st.insert(a);
        q.pop();
      } else {
        st.insert(a);
        q.push(a);
        t++;
      }
    }
  }
  cout << t << endl;
  reverseQueue(q);
  while (!q.empty()) {
    cout << q.front() << " ";
    q.pop();
  }
  return 0;
}
