#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
struct node {
  int num, id;
};
node a[200010];
int ans[200010];
int cnt = 0;
int tot = 0;
int l = 1;
bool cmp(node a1, node a2) { return a1.num > a2.num; }
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    node now;
    now.num = i;
    cin >> now.id;
    a[++tot] = now;
  }
  for (int i = 1; i <= tot; i++) {
    if (!mp[a[i].id]) {
      mp[a[i].id] = 1;
      if (cnt < k)
        ans[++cnt] = a[i].id;
      else {
        mp[ans[l]] = 0;
        l++;
        ans[++cnt] = a[i].id;
      }
    }
  }
  cout << cnt - l + 1 << endl;
  for (int i = cnt; i >= l; i--) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
