#include <bits/stdc++.h>
const long long mod = 1000000007;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  unordered_map<long long, bool> m;
  queue<long long> q;
  for (int i = 0; i < n; i++) {
    if (!m[arr[i]]) {
      if (q.size() >= k) {
        m[q.front()] = false;
        q.pop();
      }
      q.push(arr[i]);
      m[arr[i]] = true;
    }
  }
  cout << q.size() << endl;
  vector<long long> vec;
  while (!q.empty()) {
    vec.push_back(q.front());
    q.pop();
  }
  for (int i = vec.size() - 1; i >= 0; i--) {
    cout << vec[i] << " ";
  }
}
