#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> ans;
  set<int> check;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    if (check.find(temp) == check.end()) {
      if (ans.size() == k) {
        check.erase(check.find(ans[0]));
        ans.erase(ans.begin());
      }
      ans.push_back(temp);
      check.insert(temp);
    }
  }
  cout << ans.size() << endl;
  for (int i = ans.size() - 1; i >= 0; i--) {
    cout << ans[i] << " ";
  }
  return 0;
}
