#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v;
  set<int> s;
  for (int i = 0; i < n; i = i + 1) {
    int x;
    int sx = s.size();
    cin >> x;
    s.insert(x);
    if (s.size() == sx + 1) {
      if (s.size() <= k)
        v.push_back(x);
      else {
        s.erase(*v.begin());
        v.erase(v.begin());
        v.push_back(x);
      }
    }
  }
  cout << v.size() << endl;
  for (int i = v.size() - 1; i >= 0; i--) {
    cout << v[i] << " ";
  }
}
