#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k, i, a, b;
  cin >> n >> k;
  queue<int> q;
  set<int> s;
  for (i = 0; i < n; i++) {
    cin >> a;
    if (q.size() < k) {
      if (s.count(a) == 0) {
        q.push(a);
        s.insert(a);
      }
    } else {
      if (s.count(a) == 0) {
        b = q.front();
        s.erase(b);
        q.pop();
        q.push(a);
        s.insert(a);
      }
    }
  }
  n = q.size();
  int arr[n];
  for (i = (n - 1); i >= 0; i--) {
    arr[i] = q.front();
    q.pop();
  }
  cout << n << "\n";
  for (i = 0; i < n; i++) cout << arr[i] << " ";
}
