#include <bits/stdc++.h>
using namespace std;
const long long int infLL = 9000000000000000000;
const int inf = 2000000000;
const double PI = acos(-1);
const double eps = 1e-9;
const int mx = 2e5 + 125;
void solve() {
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  deque<int> dq;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (mp[a]) continue;
    if (dq.size() < k)
      dq.push_front(a), mp[a]++;
    else {
      int ck = dq.back();
      dq.pop_back();
      mp[ck]--;
      dq.push_front(a);
      mp[a]++;
    }
  }
  cout << dq.size() << '\n';
  for (auto x : dq) cout << x << " ";
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int tc;
  tc = 1;
  while (tc--) solve();
  return 0;
}
