#include <bits/stdc++.h>
using namespace std;
vector<long long> G[100000 + 100];
vector<long long> answ;
queue<long long> q;
set<long long> s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    if (s.find(x) != s.end())
      continue;
    else {
      q.push(x);
      s.insert(x);
      if (q.size() > k) {
        long long c = q.front();
        s.erase(c);
        q.pop();
      }
    }
  }
  while (!q.empty()) {
    answ.push_back(q.front());
    q.pop();
  }
  cout << answ.size() << endl;
  for (long long i = answ.size() - 1; i >= 0; i--) {
    cout << answ[i] << " ";
  }
}
