#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    vector<int> v;
    set<int> s;
    long long p, idx = 0;
    for (int i = 0; i < n; i++) {
      cin >> p;
      if (s.find(p) == s.end()) {
        if (s.size() == k) {
          s.erase(s.find(v[idx]));
          s.insert(p);
          idx++;
          v.push_back(p);
        } else {
          s.insert(p);
          v.push_back(p);
        }
      }
    }
    cout << s.size() << endl;
    int cnt = 0;
    for (int i = v.size() - 1; i >= 0; i--) {
      if (cnt >= s.size()) {
        break;
      }
      cout << v[i] << " ";
      cnt++;
    }
    cout << endl;
  }
  return (0);
}
