#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int start = 0;
  int dp[n];
  int end = 0;
  unordered_map<int, bool> arr;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (!arr[a]) {
      dp[end] = a;
      arr[a] = 1;
      if (end - start == k) {
        arr[dp[start]] = false;
        start++;
      }
      end++;
    }
  }
  cout << end - start << endl;
  for (int i = 1; i <= end - start; i++) {
    cout << dp[end - i] << " ";
  }
}
