#include <bits/stdc++.h>
using namespace std;
long long arr[1000000], numbers[1000000];
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> vi;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    vi.push_back(arr[i]);
  }
  sort(vi.begin(), vi.end());
  vector<long long> vi1;
  vi1.push_back(vi[0]);
  for (long long i = 0; i < vi.size() - 1; i++) {
    if (vi[i] != vi[i + 1]) {
      vi1.push_back(vi[i + 1]);
    }
  }
  for (long long i = 0; i < n; i++) {
    long long start = 0, finish = vi1.size() - 1, mid;
    bool found = false;
    do {
      mid = (start + finish) / 2;
      if (vi1[mid] == arr[i]) {
        found = true;
      } else if (vi1[mid] < arr[i])
        start = mid + 1;
      else {
        finish = mid - 1;
      }
    } while (!found && start <= finish);
    arr[i] = mid + 1;
  }
  deque<long long> di;
  long long large = 0;
  for (long long i = 0; i < n; i++) {
    if (large < k && numbers[arr[i]] == 0) {
      di.push_front(arr[i]);
      numbers[arr[i]]++;
      large++;
    } else if (large >= k) {
      if (numbers[arr[i]] == 0) {
        numbers[arr[i]]++;
        numbers[di[di.size() - 1]]--;
        di.push_front(arr[i]);
        di.pop_back();
      }
    }
  }
  cout << di.size() << endl;
  for (long long i = 0; i < di.size(); i++) cout << vi1[di[i] - 1] << " ";
  return 0;
}
