#include <bits/stdc++.h>
using namespace std;
int main() {
  queue<int> q;
  int n, k;
  cin >> n;
  cin >> k;
  int ar[200005];
  map<string, int> mp;
  queue<int> st;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    if (!st.size()) {
      st.push(ar[i]);
      int x = ar[i];
      string s = "";
      while (x) {
        s += x % 10 + '0';
        x /= 10;
      }
      reverse(s.begin(), s.end());
      mp[s]++;
    } else {
      int x = ar[i];
      string s = "";
      while (x) {
        s += x % 10 + '0';
        x /= 10;
      }
      reverse(s.begin(), s.end());
      if (!mp[s]) {
        if (st.size() == k) {
          int x = st.front();
          string s = "";
          while (x) {
            s += x % 10 + '0';
            x /= 10;
          }
          reverse(s.begin(), s.end());
          mp[s]--;
          st.pop();
        }
        int x = ar[i];
        string s = "";
        while (x) {
          s += x % 10 + '0';
          x /= 10;
        }
        reverse(s.begin(), s.end());
        st.push(ar[i]);
        mp[s]++;
      }
    }
  }
  vector<int> v;
  while (st.size()) {
    v.push_back(st.front());
    st.pop();
  }
  cout << v.size() << endl;
  for (int i = v.size() - 1; i > -1; i--) {
    cout << v[i] << " ";
  }
  return 0;
}
