#include <bits/stdc++.h>
#ifdef LOCAL
#include "debug.h"
#define dump(...)                                                    \
    cout << "   " << string(#__VA_ARGS__) << ": "                    \
         << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \
         << endl                                                     \
         << "   ",                                                   \
        dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif

#define ll long long
#define int ll
#define BUF 1e5
#define INF 1 << 30
#define all(a) (a).begin(), (a).end()
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <ll mod>
class Fp {
public:
    ll val;

private:
    inline void calc_mod(ll &v) {
        if (v >= mod)
            v -= mod;
    }

public:
    Fp() {}
    Fp(ll v) : val(v % mod) {
        if (val < 0)
            val += mod;
    }
    Fp operator+=(const Fp &in) {
        val += in.val;
        calc_mod(val);
        return *this;
    }
    Fp operator+(const Fp &in) const {
        return Fp(*this) += in;
    }
    Fp &operator-=(const Fp &in) {
        val -= in.val;
        calc_mod(val);
        if (val < 0)
            val += mod;
        return *this;
    }
    Fp operator-(const Fp &in) const {
        return Fp(*this) -= in;
    }
    Fp &operator*=(const Fp &in) {
        val = val * in.val % mod;
        return *this;
    }
    Fp operator*(const Fp &in) const {
        return Fp(*this) *= in;
    }
    Fp &operator/=(const Fp &in) {
        *this *= modpow(in, mod - 2);
        return *this;
    }
    Fp operator/(const Fp &in) const {
        return Fp(*this) /= in;
    }
    bool operator==(const Fp &in) const {
        return val == in.val;
    }
    bool operator!=(const Fp &in) const {
        return val != in.val;
    }
    friend Fp modpow(const Fp &in, ll n) {
        if (n == 0)
            return 1;
        if (n & 1) {
            return in * modpow(in * in, n / 2);
        } else {
            return modpow(in * in, n / 2);
        }
    }

    friend istream &operator>>(istream &is, Fp<mod> &fp) {
        is >> fp.val;
        return is;
    }

    friend ostream &operator<<(ostream &os, Fp<mod> &fp) {
        os << fp.val;
        return os;
    }
};
using modll = Fp<mod>;
class Factorial {
public:
    vector<modll> fact, finv;
    Factorial(ll n) : fact(n + 1, modll(1)), finv(n + 1, modll(1)) {
        for (int i = 2; i <= n; i++) {
            modll tmp(i);
            fact[i] = fact[i - 1] * tmp;
            finv[i] = finv[i - 1] / tmp;
        }
    }
    modll com(const ll &n, const ll &k) {
        if (n < k || n < 0 || k < 0)
            return modll(0);
        return fact[n] * finv[k] * finv[n - k];
    }
};

signed main() {
    cin >> N >> K;
    vector<int> g(N);
    vector<int> a(N);
    map<int, vector<int>> mp;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        mp[a[i]].push_back(i);
    }
    for (auto kv : mp) {
        auto v = kv.second;
        for (int i = 0; i < v.size(); i++) {
            if (i == v.size() - 1) {
                if (v[0] == N - 1) {
                    g[v[i]] = 0;
                } else {
                    g[v[i]] = v[0] + 1;
                }
            } else {
                if (v[i + 1] == N - 1) {
                    g[v[i]] = 0;
                } else {
                    g[v[i]] = v[i + 1] + 1;
                }
            }
        }
    }
    set<int> st;
    int prev = 0;
    int loop_ind;
    int loop_dist = 0;
    st.insert(0);
    while (1) {
        if (g[prev] - prev == 1 || prev - g[prev] == N - 1) {
            loop_dist += N + 1;
        } else if (g[prev] > prev) {
            loop_dist += g[prev] - prev;
        } else {
            loop_dist += (N - prev) + g[prev];
        }
        if (st.count(g[prev]) == 1) {
            loop_ind = g[prev];
            break;
        } else {
            st.insert(g[prev]);
            prev = g[prev];
        }
        dump(g);
    }
    ans = (N * K - 1) % loop_dist;
    int tmp = 0;
    prev = 0;
    int mem = 0;
    int mem_ans = 0;
    while (ans > tmp) {
        mem_ans = tmp;
        if (g[prev] - prev == 1 || prev - g[prev] == N - 1) {
            tmp += N + 1;
        } else if (g[prev] > prev) {
            tmp += g[prev] - prev;
        } else {
            tmp += (N - prev) + g[prev];
        }
        mem = prev;
        prev = g[prev];
    }
    vector<int> res;
    set<int> st1;
    int now = mem;
    ans -= mem_ans;
    for (int i = 0; i <= ans; i++) {
        if (st1.count(a[now]) == 1) {
            while (st1.count(a[now]) == 1) {
                int end = res.size() - 1;
                st1.erase(res[end]);
                res.pop_back();
            }
        } else {
            st1.insert(a[now]);
            res.push_back(a[now]);
        }
        now++;
        if (now >= N) {
            now = 0;
        }
    }
    for (int i = 0; i < res.size(); i++) {
        cout << res[i];
        if (i == res.size() - 1) {
            cout << endl;
        } else {
            cout << " ";
        }
    }
}

Measured memory_bytes: 46832