#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
  int res = 0;
  while (n && ++res) n -= n & (-n);
  return res;
}
template <class T>
void chmax(T& a, const T& b) {
  a = max(a, b);
}
template <class T>
void chmin(T& a, const T& b) {
  a = min(a, b);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, k;
  cin >> n >> k;
  queue<long long int> s;
  set<long long int> fa;
  long long int a[n];
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    if (s.empty() == true) {
      s.push(a[i]);
      fa.insert(a[i]);
    } else if (s.size() <= k && fa.find(a[i]) != fa.end())
      continue;
    else if (s.size() < k && fa.find(a[i]) == fa.end()) {
      s.push(a[i]);
      fa.insert(a[i]);
    } else {
      fa.erase(s.front());
      s.pop();
      s.push(a[i]);
      fa.insert(a[i]);
    }
  }
  cout << s.size() << endl;
  stack<long long int> ss;
  while (!s.empty()) {
    ss.push(s.front());
    s.pop();
  }
  while (!ss.empty()) {
    cout << ss.top() << " ";
    ss.pop();
  }
  return 0;
}
