#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
vector<int> ans;
int main() {
  int n, k;
  cin >> n >> k;
  int n1;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (m[a] == 1) continue;
    ans.push_back(a);
    m[a] = 1;
    n1 = ans.size();
    if (n1 > k) m[ans[n1 - 1 - k]] = 0;
  }
  reverse(ans.begin(), ans.end());
  n1 = ans.size();
  n1 = min(k, n1);
  cout << n1 << endl;
  for (int i = 0; i < n1; i++) cout << ans[i] << " ";
  return 0;
}
