#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  map<long long, long long> mp;
  deque<long long> a;
  long long n, k, d, m = 0;
  cin >> n >> k;
  for (auto i = 0; i < n; i++) {
    cin >> d;
    if (!mp[d]) {
      mp[d] = 1;
      a.push_front(d);
      if (a.size() > k) {
        mp[a.back()] = 0;
        a.pop_back();
      }
    }
  }
  cout << a.size() << "\n";
  for (const auto val : a) cout << val << " ";
  return 0;
}
