#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> arr(n);
  unordered_set<int> myset;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  queue<int> order;
  for (int i = 0; i < n; ++i) {
    if (myset.find(arr[i]) == myset.end() && order.size() < k) {
      myset.insert(arr[i]);
      order.push(arr[i]);
    } else if (myset.find(arr[i]) == myset.end() && order.size() == k) {
      int temp = order.front();
      order.pop();
      myset.erase(temp);
      i -= 1;
    } else if (myset.find(arr[i]) != myset.end()) {
      continue;
    }
  }
  cout << order.size() << endl;
  stack<int> ans;
  while (order.size() != 0) {
    ans.push(order.front());
    order.pop();
  }
  while (!ans.empty()) {
    cout << ans.top() << " ";
    ans.pop();
  }
}
