#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;
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() {
  long long n, k;
  cin >> n >> k;
  vector<long long> arr(n + 10, 0);
  for (int i = 0; i < (n); i++) cin >> arr[i];
  map<long long, long long> mp{};
  vector<long long> visited;
  long long lastid = 1;
  vector<long long> list;
  unordered_set<long long> t;
  for (int i = 0; i < (n); i++) {
    if (t.find(arr[i]) == t.end()) {
      if (visited.size() >= k) {
        t.erase(visited.front());
        visited.erase(visited.begin());
        t.insert(arr[i]);
        visited.push_back(arr[i]);
      } else {
        t.insert(arr[i]);
        visited.push_back(arr[i]);
      }
    }
  }
  cout << visited.size() << endl;
  reverse(visited.begin(), visited.end());
  for (int i = 0; i < (visited.size()); i++) cout << visited[i] << " ";
  cout << endl;
  return 0;
}
