#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  srand(time(NULL));
  ;
  int n, k;
  cin >> n >> k;
  deque<int> dq;
  set<int> s;
  vector<int> v(n);
  for (auto &x : v) cin >> x;
  for (int i = 0; i < n; ++i) {
    if (dq.size() < k) {
      if (s.count(v[i])) {
        continue;
      } else {
        s.insert(v[i]);
        dq.push_front(v[i]);
      }
    } else {
      if (s.count(v[i])) {
        continue;
      } else {
        int b = dq.back();
        dq.pop_back();
        s.erase(b);
        dq.push_front(v[i]);
        s.insert(v[i]);
      }
    }
  }
  cout << dq.size() << '\n';
  for (auto &x : dq) cout << x << ' ';
  cout << '\n';
  return 0;
}
