#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long t;
  while (a) {
    t = a;
    a = b % a;
    b = t;
  }
  return b;
}
int main() {
  {
    int n, k;
    cin >> n >> k;
    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    deque<int> q;
    set<int> s;
    for (int i = 0; i < n; i++) {
      if (*s.lower_bound(arr[i]) == arr[i]) continue;
      if (q.size() == k) {
        s.erase(q.back());
        q.pop_back();
      }
      q.push_front(arr[i]);
      s.insert(arr[i]);
    }
    cout << q.size() << endl;
    while (!q.empty()) {
      cout << q.front() << " ";
      q.pop_front();
    }
  }
}
