#include <bits/stdc++.h>
using namespace std;
long long int modpow(long long int a, long long int b,
                     long long int m = 1000000007) {
  a %= m;
  long long int res = 1;
  while (b) {
    if (b & 1) res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
long long int bpow(long long int a, long long int b) {
  long long int res = 1;
  while (b) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long int modinv(long long int a, long long int m = 1000000007) {
  return modpow(a, m - 2, m);
}
void graph(vector<vector<int> > &adj, int m) {
  int x, y;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    adj[--x].push_back(--y);
    adj[y].push_back(x);
  }
}
void solve() {
  int n, k;
  cin >> n >> k;
  deque<int> q;
  set<int> s;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    if (s.find(t) == s.end()) {
      if (s.size() == k)
        s.erase(q.back()), q.pop_back(), s.insert(t), q.push_front(t);
      else
        q.push_front(t), s.insert(t);
    }
  }
  cout << q.size() << '\n';
  for (auto elem : q) cout << elem << " ";
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) solve();
}
