#include<bits/stdc++.h> using namespace std;
queue<long long> q;
bool b[1001];
long long a[1001], n, k;
int main() { ios::sync_with_stdio(0);
cin.tie(0); cin >>n;
for (int i = 0; i < 1001; i++) b[i] = false;
for (int i = 0; i < n; i++) cin >> a[i]; cin >> k;
for (int i = 0; i < n; i++) if (!b[a[i]]) { if (q.size() < k) { b[a[i]] = true;
q.push(a[i]); } else { b[q.front()] = false;
b[a[i]] = true; q.push(a[i]);
q.pop(); } } while (!q.empty()) { cout << q.front() << " "; q.pop(); } return 0; }