#include <bits/stdc++.h>
using namespace std;
int dr[] = {-1, 1, 0, 0, -1, 1, -1, 1};
int dc[] = {0, 0, 1, -1, 1, -1, -1, 1};
int compare_double(double a, double b) {
  if (fabs(a - b) < 1e-15) return 0;
  return a > b ? 1 : -1;
}
const long long INF = 1e18;
const int N = 2e5 + 5, oo = 0x3f3f3f3f, mod = 1e9 + 7;
int a[N];
bool found(deque<int> v, int x) {
  for (int i = 0; i < v.size(); i++) {
    if (x == v[i]) return 1;
  }
  return 0;
}
void solve() {
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  deque<int> d;
  for (int i = 0; i < n; i++) {
    if (d.size() < k) {
      if (mp[a[i]] == 0) {
        d.push_front(a[i]);
        mp[a[i]]++;
      }
    } else if (d.size() == k) {
      if (mp[a[i]] == 0) {
        mp[d.back()]--;
        d.pop_back();
        d.push_front(a[i]);
        mp[a[i]]++;
      }
    }
  }
  cout << d.size() << '\n';
  for (int i = 0; i < d.size(); i++) cout << d[i] << " ";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
