#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x, k;
  cin >> n >> k;
  vector<long long> v;
  set<long long> s;
  map<long long, long long> m;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    if (m[x] == 0) {
      m[x]++;
      v.insert(v.begin(), x);
    }
    if (v.size() > k) {
      m[v.back()] = 0;
      v.pop_back();
    }
  }
  long long a = v.size();
  cout << min((a), k) << endl;
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
}
