#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i, x = 0, m, num;
  cin >> n >> k;
  map<int, int> mp;
  int arr[1000000];
  for (i = 0; (i < n) && (x < k); i++) {
    cin >> num;
    if (mp[num] == 0) {
      arr[x] = num;
      mp[num] = 1;
      x++;
    }
  }
  int j = 0;
  for (m = i; m <= (n - 1); m++) {
    cin >> num;
    if (mp[num] == 1) {
      continue;
    } else if ((mp[num] == 0) && ((x - j) != k)) {
      arr[x] = num;
      mp[num] = 1;
      x++;
    } else {
      mp[arr[j]] = 0;
      j++;
      arr[x] = num;
      x++;
      mp[num] = 1;
    }
  }
  cout << x - j << "\n";
  for (m = x - 1; m >= j; m--) {
    cout << arr[m] << " ";
  }
}
