#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
long long a[maxn];
map<int, int> m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  ;
  queue<int> q;
  vector<int> v;
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    if (m[a[i]] == 0 && q.size() < k) {
      q.push(a[i]);
      m[a[i]] = 1;
    } else if (q.size() >= k) {
      if (m[a[i]] == 0) {
        q.push(a[i]);
        m[a[i]] = 1;
        m[q.front()] = 0;
        q.pop();
      }
    }
  }
  int h = q.size();
  for (int i = 0; i < h; i++) {
    v.push_back(q.front());
    q.pop();
  }
  cout << v.size() << endl;
  for (int i = v.size() - 1; i >= 0; i--) cout << v[i] << " ";
}
