#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  set<pair<int, int>> s;
  map<int, int> m;
  int temp;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (s.size() < k && (!m.count(temp))) {
      s.insert({i + 1, temp});
      m[temp] = i + 1;
    }
    if (!m.count(temp) || (!s.count({m[temp], temp}))) {
      s.insert({i + 1, temp});
      m[temp] = i + 1;
      s.erase(*s.begin());
    }
  }
  int ar[k + 10];
  int c = 0;
  for (auto u : s) {
    ar[c] = u.second;
    c++;
  }
  cout << c << "\n";
  for (int i = c - 1; i >= 0; i--) {
    cout << ar[i] << " ";
  }
  return 0;
}
