#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3, inf = 1e18, mod = 1e9 + 7, eps = -1e8;
int tc, n, m, a, b, c, i, j, k, l, sum;
string s;
vector<int> v;
queue<int> q;
map<int, int> mp;
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> a;
    if (mp[a]) continue;
    if (q.size() >= k) b = q.front(), mp[b] = 0, q.pop();
    q.push(a);
    mp[a] = 1;
  }
  cout << q.size() << endl;
  while (!q.empty()) {
    v.push_back(q.front());
    q.pop();
  }
  for (i = v.size() - 1; i >= 0; i--) cout << v[i] << ' ';
}
