#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long lcd(long long a, long long b) { return (a * b / gcd(a, b)); }
long long powfast(long long a, long long b) {
  long long result = 1;
  while (b > 0) {
    if (b & 1) result = (result * a) % 1000000007;
    b >>= 1;
    a = (a * a) % 1000000007;
  }
  return result;
}
bool check(long long n) {
  set<long long> s;
  long long k = 0;
  while (n != 0) {
    s.insert(n % 10);
    n /= 10;
    k++;
  }
  if (s.size() != k) {
    return false;
  } else {
    return true;
  }
}
void divis(long long n, long long m) {
  vector<long long> divn;
  vector<long long> divm;
  for (long long i = 0; i * i < n; i++) {
    if (n % i == 0) {
      if (n / i != i) n /= i;
    }
  }
  for (long long i = 0; i * i < m; i++) {
    if (n % i == 0) {
      if (m / i != i) divm.push_back(m / i);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, z;
  cin >> n >> z;
  map<long long, long long> m;
  queue<long long> q;
  for (long long i = 0; i < n; i++) {
    long long k;
    cin >> k;
    if (m[k] == 0) {
      if (q.size() >= z) {
        m[q.front()] = 0;
        q.pop();
        q.push(k);
        m[k] = 1;
      } else {
        q.push(k);
        m[k] = 1;
      }
    }
  }
  vector<long long> aux;
  cout << q.size() << "\n";
  while (!q.empty()) {
    aux.push_back(q.front());
    q.pop();
  }
  for (long long i = aux.size() - 1; i >= 0; i--) {
    cout << aux[i] << " ";
  }
  cout << "\n";
}
