#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m;
  cin >> n >> m;
  long long int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  list<long long int> v;
  map<long long int, long long int> mp;
  for (int i = 0; i < n; i++) {
    int flag = 0;
    if (mp[a[i]] == 1) {
      flag++;
    }
    if (flag == 0) {
      if (v.size() == m) {
        mp[v.back()]--;
        v.pop_back();
        v.push_front(a[i]);
        mp[a[i]]++;
      } else {
        v.push_front(a[i]);
        mp[a[i]]++;
      }
    }
  }
  int count = 0;
  cout << v.size() << endl;
  for (auto i : v) cout << i << " ";
  cout << endl;
}
