#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long int power(long long int x, long long int y) {
  long long int temp;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
long long int GCD(long long int A, long long int B) {
  if (B == 0)
    return A;
  else
    return GCD(B, A % B);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  long long int n, k, i, j;
  cin >> n >> k;
  map<long long int, bool> m;
  deque<long long int> q;
  for (i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    if (m.find(x) != m.end() || m[x] == 1) {
    } else if (q.size() < k) {
      q.push_front(x);
      m[x] = 1;
    } else {
      long long int t = q[q.size() - 1];
      m.erase(t);
      q.pop_back();
      q.push_front(x);
      m[x] = 1;
    }
  }
  cout << q.size() << endl;
  for (i = 0; i < q.size(); i++) cout << q[i] << " ";
}
