#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int msgQtt, showQtt;
  cin >> msgQtt >> showQtt;
  int currShow = 0, id;
  map<int, bool> isDisplayed;
  deque<int> display;
  for (int i = 0; i < msgQtt; ++i) {
    cin >> id;
    if (isDisplayed[id]) continue;
    if (currShow == showQtt) {
      isDisplayed[display.back()] = false;
      display.pop_back();
    } else {
      currShow++;
    }
    display.push_front(id);
    isDisplayed[id] = true;
  }
  cout << display.size() << '\n';
  cout << display.front();
  display.pop_front();
  while (!display.empty()) {
    cout << " " << display.front();
    display.pop_front();
  }
  return 0;
}
