#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print(T t) {
  for (const auto &it : t) cout << it << ' ';
  cout << "\n";
}
const double Pi = acos(-1.0);
const int Mod = 1e9 + 7;
const int Eps = 1e-9;
const int Inf = 1 << 28;
const int Maxx = 1e5 + 10;
set<int> ck;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  queue<int> Q;
  for (int i = 0; i < n; i++) {
    int id;
    cin >> id;
    if (ck.find(id) == ck.end()) {
      if (int(Q.size()) == k) {
        ck.erase(Q.front());
        Q.pop();
      }
      Q.push(id);
      ck.insert(id);
    }
  }
  cout << int(Q.size()) << "\n";
  vector<int> v;
  while (Q.empty() == false) {
    v.emplace_back(Q.front());
    Q.pop();
  }
  reverse(v.begin(), v.end());
  for (auto &it : v) cout << it << ' ';
  cout << "\n";
  return 0;
}
