#include <bits/stdc++.h>
using namespace std;
const char nl = '\n';
const long long mod = 998244353;
const int inf = 1e9 + 5;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  set<int> s;
  deque<int> q;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (s.count(x)) continue;
    if (q.size() >= k) {
      int tmp = q.back();
      s.erase(tmp);
      q.push_front(x);
      q.pop_back();
    } else {
      q.push_front(x);
    }
    s.insert(x);
  }
  cout << s.size() << nl;
  for (int i = 0; i < s.size(); i++) {
    cout << q.front() << " ";
    q.pop_front();
  }
}
