#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;
  vector<int> d(n);
  queue<int> qq;
  unordered_set<int> ss;
  for (int i = 0; i < n; i++) {
    int tp;
    cin >> tp;
    if (ss.find(tp) == ss.end()) {
      if (qq.size() == k) {
        ss.erase(qq.front());
        qq.pop();
      }
      qq.push(tp);
      ss.insert(tp);
    }
  }
  stack<int> ans;
  cout << qq.size() << "\n";
  while (qq.size()) {
    ans.push(qq.front());
    qq.pop();
  }
  while (ans.size()) {
    cout << ans.top() << " ";
    ans.pop();
  }
  return 0;
}
