#include <bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

const int MAX_N=10e6+5;
int n,k,a[MAX_N];
map<int,int> mp;
vector<int> res;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for(int i=0;i<n;++i){
    cin >> a[i];
    ++mp[a[i]];
    if(mp[a[i]]==k){
        res.push_back(a[i]);
    }
  }
  cout << res.size() << endl;
  for(auto i:res){
    cout << i << " ";
  }
  return 0;
}