#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  while (cin >> n >> k) {
    set<int> s;
    int l = 0, r = 0;
    int ans[200005];
    int a;
    while (n--) {
      cin >> a;
      if (s.count(a)) {
        continue;
      }
      s.insert(a);
      ans[r++] = a;
      if (r > k) {
        s.erase(ans[l++]);
      }
    }
    n = min(r - l, k);
    cout << n << '\n';
    while (n--) {
      cout << ans[--r] << ' ';
    }
    cout << '\n';
  }
}
