#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int T = 1, n, m;
  string str;
  while (T--) {
    long long int p = 0, tmp = 0, sum = 0, count = 0;
    int flag = 0;
    cin >> n >> m;
    long long int a[n];
    for (long long int i = 0; i < n; i++) cin >> a[i];
    set<long long int> second;
    queue<long long int> q;
    for (int i = 0; i < n; ++i) {
      if (second.count(a[i]) == 0) {
        second.insert(a[i]);
        if (q.size() < m) {
          q.push(a[i]);
        } else {
          tmp = q.front();
          second.erase(tmp);
          q.pop();
          q.push(a[i]);
        }
      }
    }
    cout << q.size() << "\n";
    string res = "";
    while (!q.empty()) {
      tmp = q.front();
      q.pop();
      res = to_string(tmp) + " " + res;
    }
    cout << res << "\n";
  }
  return 0;
}
