// ROOT : DRAGON3012009
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define el "\n"
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define __ROOT__ int main()
#pragma GCC optimize("O2")
#define FOR(i,l,r) for(int i = l ; i <= r ; i ++)
#define FORD(i,r,l) for(int i = r ; i >= l ; i --)
#define REP(i, a ) for(int i = 0 ; i < a ; i ++ )
#define fi first
#define se second
#define M 1000000007
#define MAXN 80001
#define INF (1ll<<30)
#define BLOCK_SIZE 800
#define MAX_NODE 1001001
#define LOG 19
#define ALPHA_SIZE 26
#define BASE 311
#define NAME "file"
#define compare(v) sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end());
using namespace std;
const ll MOD[] = {(ll)1e9 + 2277, (ll)1e9 + 5277, (ll)1e9 + 8277, (ll)1e9 + 9277, (ll) 1e9 + 7 };
const ll NMOD = 1;
const int dx[] = {-1, 0, 1,0};
const int dy[] = {0, 1, 0, -1};

//**Variable**//
ll n, num_color = 0, que ;
ll c[MAXN];
ll high[MAXN] ;
ll deg[MAXN] ;
ll dis[MAXN / BLOCK_SIZE][MAXN] ;
vector<ll> adj[MAXN] ;
vector<ll> color[MAXN] ;
bool heavy[MAXN] ;
vector<ll> cpr;
unordered_map<ll,ll> mp ;

// For LCA with RMQ
vector<int> euler, depth, first(MAXN);
int st[LOG+1][2 * MAXN];
int lg[2 * MAXN];

//**Function**//
template<class X, class Y >
bool minimize(X & x, const Y &y ) { return x > y ? x = y, 1:0 ; }
template<class X, class Y >
bool maximize(X &x, const Y &y ) { return x < y ? x = y, 1:0 ; }

void dfs_euler(int u, int p, int d) {
    first[u] = euler.size();
    euler.push_back(u);
    depth.push_back(d);
    for (int v : adj[u]) if (v != p) {
        dfs_euler(v, u, d + 1);
        euler.push_back(u);
        depth.push_back(d);
    }
}

void build_sparse() {
    int m = euler.size();
    for (int i = 0; i < m; ++i) st[0][i] = i;
    for (int i = 2; i <= m; ++i) lg[i] = lg[i / 2] + 1;
    for (int k = 1; (1 << k) <= m; ++k) {
        for (int i = 0; i + (1 << k) <= m; ++i) {
            int x = st[k - 1][i];
            int y = st[k - 1][i + (1 << (k - 1))];
            st[k][i] = (depth[x] < depth[y] ? x : y);
        }
    }
}

int LCA(int u, int v) {
    int L = first[u], R = first[v];
    if (L > R) swap(L, R);
    int k = lg[R - L + 1];
    int x = st[k][L], y = st[k][R - (1 << k) + 1];
    return (depth[x] < depth[y]) ? euler[x] : euler[y];
}

ll dist(ll u, ll v) {
    return depth[first[u]] + depth[first[v]] - 2 * depth[first[LCA(u, v)]];
}

void bfs(ll co) {
    queue<ll> q ;
    for(ll v : color[co ]) {
        dis[co][v] = 0 ;
        q.push(v) ;
    }
    while(!q.empty()) {
        ll u = q.front() ; q.pop() ;
        for(ll v : adj[u]) {
            if(dis[co][v] == 0 && v != u) {
                dis[co][v] = dis[co][u] + 1 ;
                q.push(v) ;
            }
        }
    }
}

void init() {
    cin>>n >> que ;
    FOR(i,1, n) cin >> c[i], cpr.push_back(c[i]), mp[c[i]]++;
    compare(cpr) ;
    num_color = cpr.size() ;
    FOR(i, 1,n) {
        c[i] = lower_bound(cpr.begin(), cpr.end(), c[i]) - cpr.begin() + 1;
        deg[c[i]] ++ ;
        color[c[i]].push_back(i) ;
    }
    FOR(i, 1, n -1 ) {
        ll x, y ; cin >> x>> y ;
        adj[x].push_back(y) ;
        adj[y].push_back(x) ;
    }
    // LCA preprocess
    dfs_euler(1, 0, 0);
    build_sparse();
    FOR(i, 1, num_color) if(deg[i] >= BLOCK_SIZE ) bfs(i) ;
}

void solve() {
    FOR(i, 1,que ) {
        ll u, c ; cin >> u >> c ;
        if(mp[c] == 0 ) {
            cout << -1 << el ;
            continue ;
        }
        c = lower_bound(cpr.begin(), cpr.end(), c  ) - cpr.begin() + 1 ;
        if(deg[c] >= BLOCK_SIZE) cout << dis[c][u] << el ;
        else  {
            ll ans = INF ;
            for(ll v : color[c]) minimize(ans, dist(u, v )) ;
            cout << ans << el ;
        }
    }
}

__ROOT__ {
    fast;
    int t =1 ;
    while(t-- ) {
        init();
        solve();
    }
}