#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  set<pair<int, int> > have;
  int id = 0;
  for (int i = 0, a; i < n; i++) {
    cin >> a;
    if (mp.find(a) == mp.end()) {
      mp[a] = id;
      have.insert({id++, a});
    } else {
      if (mp[a] >= max(0, (int)have.size() - k)) {
        continue;
      }
      mp[a] = id;
      have.insert({id++, a});
    }
  }
  if (have.empty()) {
    cout << "0\n";
    exit(0);
  }
  auto it = have.end();
  it--;
  vector<int> res;
  for (int i = 1; i <= k; i++) {
    res.push_back((*it).second);
    if (it == have.begin()) break;
    it--;
  }
  cout << res.size() << "\n";
  for (int i : res) {
    cout << i << " ";
  }
  cout << "\n";
}
