#include <bits/stdc++.h>
using namespace std;
void FASTIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int main() {
  int n, k;
  cin >> n >> k;
  set<int> friendsIds;
  queue<int> conversations;
  for (int idx = 0; idx < n; idx++) {
    int friendId;
    cin >> friendId;
    if (friendsIds.count(friendId))
      continue;
    else {
      if (conversations.size() == k) {
        int lastFriendId = conversations.front();
        friendsIds.erase(lastFriendId);
        conversations.pop();
      }
      conversations.push(friendId);
      friendsIds.insert(friendId);
    }
  }
  vector<int> friends;
  while (!conversations.empty()) {
    int front = conversations.front();
    friends.push_back(front);
    conversations.pop();
  }
  cout << friends.size() << "\n";
  for (int idx = friends.size() - 1; idx >= 0; idx--) {
    cout << friends[idx] << " ";
  }
}
