#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  queue<int> stk;
  set<int> in;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (in.find(x) != in.end())
      continue;
    else {
      if (stk.size() == k) {
        int tmp = stk.front();
        stk.pop();
        in.erase(tmp);
        stk.push(x);
        in.insert(x);
      } else {
        stk.push(x);
        in.insert(x);
      }
    }
  }
  cout << stk.size() << endl;
  vector<int> out;
  while (stk.empty() == 0) {
    out.push_back(stk.front());
    stk.pop();
  }
  for (int i = out.size() - 1; i >= 0; i--) cout << out[i] << " ";
}
