#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
int check[N];
queue<int> q;
vector<int> ans;
set<int> s;
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  fast();
  int n, k;
  cin >> n >> k;
  int x;
  while (n--) {
    cin >> x;
    if (s.find(x) == s.end()) {
      s.insert(x);
      if (q.size() == k) {
        s.erase(q.front());
        q.pop();
      }
      q.push(x);
    }
  }
  cout << q.size() << endl;
  while (!q.empty()) {
    ans.push_back(q.front());
    q.pop();
  }
  for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i] << " ";
}
