#include <bits/stdc++.h>
using namespace std;
const int N = 1e9;
void showdq(deque<int> g) {
  deque<int>::iterator it;
  for (it = g.begin(); it != g.end(); ++it) cout << *it << " ";
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  deque<int> stk;
  int n;
  cin >> n;
  int k;
  cin >> k;
  int size = min(n, k);
  map<long long, int> id;
  for (int i = 0; i < n; i++) {
    long long data;
    cin >> data;
    if (id[data] == 1) {
      continue;
    } else {
      id[data] = 1;
      if (stk.size() < k) {
        stk.push_front(data);
      } else if (stk.size() == k) {
        id[stk.back()] = 0;
        stk.pop_back();
        stk.push_front(data);
      }
    }
  }
  cout << stk.size() << "\n";
  showdq(stk);
  return 0;
}
