#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long x;
    map<long long, long long> m;
    deque<long long> q;
    for (long long i = 0; i < n; i++) {
      cin >> x;
      if (q.size() < k) {
        if (m.find(x) == m.end()) {
          q.push_back(x);
          m[x]++;
        }
      } else {
        if (m.find(x) == m.end()) {
          m[q.front()] -= 1;
          if (m[q.front()] == 0) m.erase(q.front());
          q.pop_front();
          m[x]++;
          q.push_back(x);
        }
      }
    }
    cout << q.size() << "\n";
    while (!q.empty()) {
      cout << q.back() << " ";
      q.pop_back();
    }
  }
  return 0;
}
