#define _CRT_SECURE_NO_WARNINGS
#define MOD 1000000007
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <functional>
#include <algorithm>
#include <iterator>
#include <cstdio>
#include <utility>
#include <unordered_map>
#include <cmath>
#include <chrono>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll, ll> P;
struct edge { ll to, cost; };

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,-1)

inline ll madd(ll a, ll b) {
	a %= MOD;b %= MOD;
	return (a + b) % MOD;
}
inline ll msub(ll a, ll b) {
	a %= MOD;b %= MOD;
	a += MOD;
	return (a - b) % MOD;
}
inline ll mmul(ll a, ll b) {
	a %= MOD;b %= MOD;
	return (a*b) % MOD;
}
inline ll mpow(ll a, ll r) {
	long long res = 1;
	while (r > 0) {
		if (r & 1) res = res * a % MOD;
		a = a * a % MOD;
		r >>= 1;
	}
	return res;
}
inline ll minv(ll a) {
	a %= MOD;
	ll b = MOD, u = 0, v = 1;
	while (a) {
		ll t = b / a;
		b -= t * a; swap(a, b);
		u -= t * v; swap(u, v);
	}
	if (u < 0) u += MOD;
	return u;
}
inline ll mdiv(ll a, ll b) {
	a %= MOD;
	a *= minv(b);
	return a%MOD;
}

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

/*int V;
vector<edge> G[MAX_V];
int d[MAX_V]:
void dijkstra(int s) {
priority_queue<P, vector<P>, greater<P>> q;
fill(d, d + V, INF);


}*/


//ll fact[100001], fact_inv[100001];
/*
ll combi(int a, int b) {
	return mmul(fact[a], mmul(fact_inv[b], fact_inv[a - b]));
}
*/
int heads[500000];
int main(void) {
	map<int, vector<int>> mp;
	ll n, k;
	cin >> n >> k;
	vector<int> a(n);
	REP(i, n) {
		cin >> a[i];
		mp[a[i]].push_back(i);
	}
	int head = -1,cnt=0;
	do{
		for(int ind=0;;){
			if(ind==0){
				if (head == -1) {
					head = a[0];
				}
				else {
					ind = mp[head][0]+1;
					if (ind == n) {
						head = -1;
						break;
					}
					head = a[ind];
				}
			}
			auto v = mp[head];
			auto it = lower_bound(v.begin(),v.end(), ind);
			it++;
			if (it == v.end()) {
				break;
			}else{
				ind = *it+1;
				if (ind == n) {
					head = -1;
					break;
				}
				head = a[ind];
			}
		}
		heads[cnt+1] = head;
		cnt++;
	} while (head >= 0);
	k %= cnt;

	if (k !=0){
		/*head = -1;
		REP(i, k - 1) {
			for (int ind = 0;;) {
				if (ind == 0) {
					if (head == -1) {
						head = a[0];
					}
					else {
						ind = mp[head][0] + 1;
						if (ind == n) {
							head = -1;
							break;
						}
						head = a[ind];
					}
				}
				auto v = mp[head];
				auto it = lower_bound(v.begin(), v.end(), ind);
				it++;
				if (it == v.end()) {
					break;
				}
				else {
					ind = *it + 1;
					if (ind == n) {
						head = -1;
						break;
					}
					head = a[ind];
				}
			}
		}*/
		head = -1;
		if (k>1){
			head = heads[k - 1];
		}
		vector<int> res;
		for (int ind = 0;;) {
			if (ind == 0) {
				if (head == -1) {
					head = a[0];
				}
				else {
					ind = mp[head][0] + 1;
					head = a[ind];
				}
			}
			auto v = mp[head];
			auto it = lower_bound(v.begin(), v.end(), ind);
			it++;
			if (it == v.end()) {
				it--;
				res.push_back(head);
				ind = *it + 1;
				if (ind == n) {
					head = -1;
					break;
				}
				head = a[ind];
			}
			else {
				ind = *it + 1;
				if (ind == n) {
					head = -1;
					break;
				}
				head = a[ind];
			}
		}
		for (auto i : res) {
			cout << i << " ";
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 25844