#include <bits/stdc++.h>
using namespace std;
const long long N = (int)2e5 + 7, MOD = (int)1e9 + 7;
int n, k;
pair<int, int> a[N];
bool col[N];
vector<int> v;
map<int, int> mp, val;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
int main() {
  ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + n + 1);
  int cnt = 1;
  for (int i = 1; i <= n; i++) {
    if (mp[a[i].first] == 0) {
      mp[a[i].first] = cnt;
      val[cnt] = a[i].first;
      cnt++;
    }
    a[i].first = mp[a[i].first];
  }
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    if (col[a[i].first] == 0) {
      col[a[i].first] = 1;
      if ((int)v.size() >= k) {
        col[v[(int)v.size() - k]] = 0;
      }
      v.push_back(a[i].first);
    }
  }
  cout << min(k, (int)v.size()) << "\n";
  for (int i = (int)v.size() - 1; i >= max((int)v.size() - k, 0); i--) {
    cout << val[v[i]] << ' ';
  }
  exit(0);
}
