#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, k;
deque<int> q;
map<int, int> used;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int id;
    cin >> id;
    if (used[id] == 1) {
      continue;
    }
    if (q.size() == k) {
      int a = q.back();
      q.pop_back();
      used[a]--;
    }
    q.push_front(id);
    used[id]++;
  }
  cout << q.size() << endl;
  while (!q.empty()) {
    cout << q.front() << " ";
    q.pop_front();
  }
}
