#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, k;
  cin >> n >> k;
  long long int i;
  long long int x;
  map<long long int, long long int> answer;
  vector<long long int> answer1;
  int ans = 0;
  for (i = 0; i < n; i++) {
    cin >> x;
    if (!answer[x]) {
      answer1.push_back(x);
      if (answer1.size() > k) {
        long long int element = answer1[ans];
        ans++;
        answer[element] = 0;
      }
      answer[x] = 1;
    }
  }
  vector<int> printAnswer;
  for (i = ans; i < answer1.size(); i++) {
    printAnswer.push_back(answer1[i]);
  }
  reverse(printAnswer.begin(), printAnswer.end());
  cout << printAnswer.size() << endl;
  for (i = 0; i < printAnswer.size(); i++) {
    cout << printAnswer[i] << " ";
  }
  cout << endl;
  return 0;
}
