#include <bits/stdc++.h>
using namespace std;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
const double EPS = 1e-9;
int cmp(double x, double y = 0, double tol = EPS) {
  return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
void showq(queue<int> gq) {
  std::vector<int> temp;
  queue<int> g = gq;
  while (!g.empty()) {
    temp.push_back(g.front());
    g.pop();
  }
  for (int j = temp.size() - 1; j != -1; j--) {
    cout << temp[j] << " ";
  }
}
int main() {
  int n, k;
  scanf("%d", &n);
  scanf("%d", &k);
  queue<int> screen;
  set<int> myset;
  vector<int> input;
  for (int i = (0); i < (n); ++i) {
    int t;
    cin >> t;
    input.push_back(t);
  }
  for (int j = (0); j < (input.size()); ++j) {
    if (screen.size() < k) {
      if (myset.find(input[j]) == myset.end()) {
        screen.push(input[j]);
        myset.insert(input[j]);
      }
    } else {
      if (myset.find(input[j]) == myset.end()) {
        myset.erase(screen.front());
        screen.pop();
        screen.push(input[j]);
        myset.insert(input[j]);
      }
    }
  }
  cout << screen.size() << endl;
  showq(screen);
  return 0;
}
