#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
map<long long, long long> mp;
long long b[N];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int p = 0;
  int pp = 0;
  for (int i = 0; i < n; i++) {
    long long a;
    scanf("%lld", &a);
    if (p < k) {
      if (mp[a] == 0) {
        b[p++] = a;
        mp[a] = 1;
      }
    } else {
      if (mp[a] == 0) {
        b[p++] = a;
        mp[a] = 1;
        mp[b[pp++]] = 0;
      }
    }
  }
  printf("%d\n", p - pp);
  for (int j = p - 1; j >= pp; j--) printf("%lld ", b[j]);
}
