#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
  long long temp;
  if (y == 0) return 1;
  temp = power(x, y / 2) % 1000000007;
  if (y % 2 == 0)
    return (temp % 1000000007 * temp % 1000000007) % 1000000007;
  else
    return ((x % 1000000007) *
            ((temp % 1000000007 * temp % 1000000007) % 1000000007)) %
           1000000007;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> v(n + 1);
  for (long long i = 1; i <= n; i++) cin >> v[i];
  map<long long, long long> m;
  queue<long long> q;
  for (long long i = 1; i <= n; i++) {
    if (m[v[i]] == 0) {
      if (q.size() < k) {
        q.push(v[i]);
        m[v[i]] = 1;
      } else {
        long long temp = q.front();
        m[temp] = 0;
        q.pop();
        q.push(v[i]);
        m[v[i]] = 1;
      }
    }
  }
  cout << q.size() << "\n";
  vector<long long> temp;
  while (!q.empty()) {
    temp.push_back(q.front());
    q.pop();
  }
  reverse(temp.begin(), temp.end());
  for (auto i : temp) cout << i << " ";
  cout << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
