#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d", &n);
  scanf("%d", &k);
  vector<int> arr;
  map<int, int> amt;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    bool ada = false;
    if (amt.count(x) > 0 && amt[x] > 0) ada = true;
    if (!ada) {
      if (amt.count(x) == 0)
        amt[x] = 1;
      else
        amt[x] = amt[x] + 1;
      if ((int)arr.size() - k >= 0) {
        amt[arr[(int)arr.size() - k]] = amt[arr[(int)arr.size() - k]] - 1;
      }
      arr.push_back(x);
    }
  }
  int o[k];
  int io = 0;
  for (int i = arr.size() - 1; i > (int)arr.size() - 1 - k && i >= 0; i--) {
    o[io] = arr[i];
    io++;
  }
  cout << io << endl;
  for (int i = 0; i < io; i++) {
    printf("%d", o[i]);
    if (i != io - 1) printf(" ");
  }
  printf("\n");
}
