#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 200;
template <class Ruby>
inline void read(Ruby &x) {
  x = 0;
  char ch = getchar(), w = 0;
  while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  x = w ? -x : x;
}
map<int, int> visited;
int n, k;
queue<int> q;
int ans[N];
int main() {
  read(n), read(k);
  for (register int i = 1, qa; i <= n; i++) {
    read(qa);
    if (!visited[qa]) {
      visited[qa] = 1;
      q.push(qa);
      if (q.size() > k) {
        visited[q.front()] = 0;
        q.pop();
      }
    }
  }
  int s = q.size();
  cout << s << endl;
  for (register int i = s; i >= 1; i--) {
    ans[i] = q.front();
    q.pop();
  }
  for (register int i = 1; i <= s; i++) printf("%d ", ans[i]);
  return 0;
}
