#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int mex = 1e5 + 1;
long long int power(long long int a, long long int b) {
  long long int ans = 1, t = a;
  while (b) {
    if (b & 1) ans = (ans * t) % mod;
    t = (t * t) % mod;
    b = b >> 1;
  }
  return ans;
}
int d, x, y;
void extendedEuclid(int A, int B) {
  if (B == 0) {
    d = A;
    x = 1;
    y = 0;
  } else {
    extendedEuclid(B, A % B);
    int temp = x;
    x = y;
    y = temp - (A / B) * y;
  }
}
int main() {
  vector<int> v;
  int n, k;
  cin >> n >> k;
  int arr[n], cnt = 0;
  for (int i = 0; i < n; i++) cin >> arr[i];
  map<int, int> mp;
  v.push_back(arr[0]);
  mp[arr[0]]++;
  for (int i = 1; i < n; i++) {
    if (mp[arr[i]] == 0) {
      if (v.size() >= k) mp[v[v.size() - k]]--;
      v.push_back(arr[i]);
      mp[arr[i]]++;
    }
  }
  if (v.size() > k) {
    cout << k << endl;
    for (int i = 1; i <= k; i++) cout << v[v.size() - i] << " ";
  } else {
    cout << v.size() << endl;
    for (int i = 1; i <= v.size(); i++) cout << v[v.size() - i] << " ";
  }
}
