#include <bits/stdc++.h>
using namespace std;
const long long mod = (1 ? 998244353 : 1000000007);
const long long N = 2;
const long long inf = 1 << 30;
const long long llf = 9e18;
long long powmod(long long a, long long b, long long pp = mod) {
  long long res = 1;
  a %= pp;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % pp;
    a = a * a % pp;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long mul(long long a, long long b, long long pp = mod) {
  long long ans = 0;
  for (; b; b >>= 1) {
    if (b & 1) ans = (ans + a) % pp;
    a = a * 2 % pp;
  }
  return ans;
}
struct node {
  long long x, y, z, time;
  long long no, w, h;
  long long pre, nxt;
  friend bool operator<(const node& a, const node& b) { return a.y > b.y; }
};
bool cmp(long long x, long long y) { return x > y; }
inline long long min(long long a, long long b) {
  if (a > b)
    return b;
  else
    return a;
}
inline long long max(long long a, long long b) {
  if (a < b)
    return b;
  else
    return a;
}
inline void upmax(long long& a, long long b) {
  if (a < b) a = b;
};
inline void upmin(long long& a, long long b) {
  if (a > b) a = b;
};
long long dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
long long dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
map<long long, long long> book;
long long ans[200100];
signed main() {
  ios::sync_with_stdio(false);
  long long _ = 1;
  while (_--) {
    long long n, k;
    cin >> n >> k;
    queue<long long> q;
    long long a;
    long long now = 0;
    for (long long i = 1; i <= n; ++i) {
      cin >> a;
      if (book[a] == 0) {
        q.push(a);
        book[a] = 1;
        now++;
      }
      if (now > k) {
        book[q.front()] = 0;
        q.pop();
        now--;
      }
    }
    cout << now << endl;
    for (long long i = 1; i <= now; ++i) {
      ans[now - i + 1] = q.front();
      q.pop();
    }
    for (long long i = 1; i <= now; ++i) cout << ans[i] << " ";
  }
  return 0;
}
