#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 + 200;
const int MAXN = 2 * 100 * 100 + 20;
const int MLOG = 18;
const int NMAX = 1 * 1000;
int main() {
  ios_base::sync_with_stdio(false);
  ;
  int n, k, a;
  cin >> n >> k;
  map<int, int> mp;
  deque<int> dq;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (mp[a]) continue;
    mp[a]++;
    dq.push_back(a);
    if ((int)(dq.size()) > k) mp[dq.front()]--, dq.pop_front();
  }
  cout << (int)(dq.size()) << endl;
  for (int i = 0; i < (int)(dq.size()); i++)
    cout << dq[(int)(dq.size()) - i - 1] << ' ';
}
