#include <bits/stdc++.h>
using namespace std;
queue<int> q;
void reverseQueue() {
  stack<int> Stack;
  while (!q.empty()) {
    Stack.push(q.front());
    q.pop();
  }
  while (!Stack.empty()) {
    q.push(Stack.top());
    Stack.pop();
  }
}
int main() {
  map<int, int> m;
  int n, k;
  cin >> n >> k;
  while (n--) {
    int a;
    cin >> a;
    if (m[a] == 0) {
      if (q.size() == k) {
        m[q.front()] = 0;
        q.pop();
        q.push(a);
        m[a] = 1;
      } else {
        q.push(a);
        m[a] = 1;
      }
    }
  }
  cout << q.size() << endl;
  reverseQueue();
  while (!q.empty()) {
    cout << q.front() << " ";
    q.pop();
  }
  cout << endl;
  return 0;
}
