#include <bits/stdc++.h>
using namespace std;
map<int, bool> vis;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, a[200005];
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  queue<int> q;
  for (int i = 0; i < n; i++) {
    if (q.size() == m) {
      if (!vis[a[i]]) {
        vis[q.front()] = 0;
        q.pop();
        q.push(a[i]);
        vis[a[i]] = 1;
      }
    } else if (q.size() < m && !vis[a[i]]) {
      q.push(a[i]);
      vis[a[i]] = 1;
    }
  }
  cout << min((int)q.size(), m) << endl;
  int cnt = q.size();
  vector<int> v;
  for (int i = 0; i < cnt; i++) {
    v.push_back(q.front());
    q.pop();
  }
  reverse(v.begin(), v.end());
  for (int i = 0; i < min(cnt, m); i++) {
    cout << v[i] << " ";
  }
  return 0;
}
