#include <bits/stdc++.h>
using std::bitset;
using std::cerr;
using std::cin;
using std::cout;
using std::deque;
using std::endl;
using std::fill;
using std::fixed;
using std::ios_base;
using std::iterator;
using std::map;
using std::max_element;
using std::min_element;
using std::multimap;
using std::multiset;
using std::pair;
using std::queue;
using std::reverse;
using std::set;
using std::setprecision;
using std::sort;
using std::stable_sort;
using std::stack;
using std::string;
using std::swap;
using std::unique;
using std::vector;
namespace MySpace {};
int n, k;
int id[500000];
map<int, int> kek;
int ray[800000];
signed main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTCASES = 1;
  cin >> n >> k;
  for (int(i) = 0; (i) != (n); (i)++) cin >> id[i];
  int l = 500000, r = 499999;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (kek[id[i]] == 1) {
      continue;
    } else {
      if (cnt == k) {
        l--;
        kek[id[i]] = 1;
        ray[l] = id[i];
        kek[ray[r]] = 0;
        r--;
      } else {
        cnt++;
        kek[id[i]] = 1;
        l--;
        ray[l] = id[i];
      }
    }
  }
  cout << cnt << "\n";
  for (int i = l; i <= r; i++) cout << ray[i] << " ";
}
