#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(998244353);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (a) - 1; (i) >= (b); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int multipf(vector<string>& s){
    if(s.size() == 0)return 0;
    cout << s[0];
    rep1(i, s.size() - 1)cout << " " << s[i];
    cout << endl;
    return 0;
}

int multipf(vector<ll>& n){
    if(n.size() == 0)return 0;
    cout << n[0];
    rep1(i, n.size() - 1)cout << " " << n[i];
    cout << endl;
    return 0;
}

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}
 
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b, ll m){
    ll ans = 1;
    while(b) {
        if(b & 1LL) ans = ans * a % m;
        ans %= m;
        a = a * a;
        a %= m;
        b >>= 1;
    }
    return ans % m;
}

vector<bool> fcolor(100000,false),f(100000,false);
vl color(100000);
vvl g(100000,vl(0));
vl ans(0);

int dfs(ll n){
    f[n] = true;
    bool ff = false;
    if(!fcolor[color[n]]){
        ans.push_back(n + 1);
        ff = true;
    }
    fcolor[color[n]] = true;
    rep0(i, g[n].size()){
        if(!f[g[n][i]])dfs(g[n][i]);
    }
    if(ff)fcolor[color[n]] = false;
    return 0;
}

//modを確認すること
int main() {
    ll n;
    cin >> n;
    rep0(i, n)cin >> color[i];
    rep0(i, n - 1){
        ll a,b;
        cin >> a >> b;
        --a;
        --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0);
    sort(all(ans));
    rep0(i, ans.size())pf(ans[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
#define num_l(a,v) POSL(a,v) //v未満の要素数
#define num_eql(a,v) POSU(a,v) //v以下の要素数
#define num_h(a,v) (a.size() - POSU(a,v)) //vより大きい要素数
#define num_eqh(a,v) (a.size() - POSL(a,v)) //v以上の要素数
// static_cast< long long ll >



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin >> n >> m;

	vector<int> A(n);
	FOR(i,0,n){
		cin >> A[i];
	}

	map<int,int> in,no;

	FOR(i,0,n+1)no[i] = 1;

	int ans = n;
	FOR(i,0,m){
		in[ A[i] ]++;
		if(in[A[i]] == 1){
			no.erase(A[i]);
		}
	}

	ans = min( ans, (*no.begin()).first );

	FOR(i,m,n){
		in[A[i]]++;
		if(in[A[i]] == 1){
			no.erase(A[i]);
		}

		in[A[i-m]]--;
		if(in[A[i-m]] == 0){
			no[A[i-m]] = 1; 
		}

		ans = min( ans, (*no.begin()).first );

	}


	cout << ans << endl;
}