#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
double PI = 3.1415926536;
const int inf = 1e9 + 7;
long long MAX(long long a, long long b) { return a > b ? a : b; }
long long MIN(long long a, long long b) { return a > b ? b : a; }
inline bool ispalindrome(string s) {
  int n = s.length(), i = 0, j = n - 1;
  while (i <= j) {
    if (s[i] != s[j]) return false;
    i++, j--;
  }
  return true;
}
inline bool isprime(long long n) {
  if (n % 2 == 0) return false;
  for (int i = 3; i * i <= n; i += 2)
    if (n % i == 0) return false;
  return true;
}
void solve() {
  int n, k;
  cin >> n >> k;
  queue<int> q;
  set<int> vals;
  for (int i = 0; i < n; ++i) {
    int id;
    cin >> id;
    if (!vals.count(id)) {
      if (int(q.size()) >= k) {
        int cur = q.front();
        q.pop();
        vals.erase(cur);
      }
      vals.insert(id);
      q.push(id);
    }
  }
  vector<int> res;
  while (!q.empty()) {
    res.push_back(q.front());
    q.pop();
  }
  reverse(res.begin(), res.end());
  cout << res.size() << "\n";
  for (auto it : res) cout << it << " ";
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
    cout << "\n";
  }
  return 0;
}
