#include <bits/stdc++.h>
using namespace std;
int arr[2 * 100005];
int arr2[2 * 100005];
int main() {
  queue<int> qu;
  map<int, int> mp;
  map<int, int>::iterator it;
  set<int> st;
  int n, k;
  scanf("%d", &n);
  scanf("%d", &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    st.insert(arr[i]);
  }
  for (int i = 0; i < n; i++) {
    if (qu.size() < k) {
      if (mp.count(arr[i]) == 0) {
        mp.insert(make_pair(arr[i], arr[i]));
        qu.push(arr[i]);
      }
    } else {
      if (mp.count(arr[i]) == 0) {
        int p = qu.front();
        mp.erase(p);
        qu.pop();
        qu.push(arr[i]);
        mp[arr[i]] = arr[i];
      }
    }
  }
  cout << qu.size() << endl;
  ;
  int gg = 0;
  while (!qu.empty()) {
    arr2[gg++] = qu.front();
    qu.pop();
  }
  for (int i = gg - 1; i >= 0; i--) {
    printf("%d ", arr2[i]);
  }
}
