/*Coded by::
**Avinash Tiwary**
**BE/10298/2015**
**Production Engineer**
**Producing <code>**
*/
#include<bits/stdc++.h>
#define buf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double dob;
#define MAX 50010
#define M5 200009
#define M6 2000009
#define M 1000000007
#define INF 1e18
using namespace std;
typedef vector<ll> V;
typedef queue<ll > Q;
typedef stack<ll> S;
typedef pair<ll,ll> P;
#define mp make_pair
#define mt make_tuple
#define pb push_back
ll n,block,ar[M5],st[M5],en[M5],dep[M5],out[M5],par[M5][20],con[M5],conr[M6],answer=0,timer=0,kha[M5];
struct query{
ll l,r,i,p;
}q[M5];
bool comp(query a,query b){
if(a.l/block!=b.l/block) return a.l<b.l;
return a.r<b.r;
}
vector<list<ll> >g(M5);
void dfs(ll cur,ll p){
dep[cur]=dep[p]+1;
par[cur][0]=p;
timer++;
st[cur]=timer;
kha[timer]=cur;
for(auto it=g[cur].begin();it!=g[cur].end();it++) if(*it!=p) dfs(*it,cur);
timer++;
en[cur]=timer;
kha[timer]=cur;
}
void preLCA(){
for(ll i=1;i<log2(n)+1;i++){
for(ll j=1;j<=n;j++){
if(par[j][i-1]!=-1)
par[j][i]=par[par[j][i-1]][i-1];
}
}
}
ll lca(ll u,ll v){
if(dep[u]>dep[v]) swap(u,v);
ll dif=dep[v]-dep[u];
while(dif>0){
ll up=log2(dif);
v=par[v][up];
dif-=(1<<up);
}
if(u==v) return u;
for(ll i=log2(n)+1;i>=0;i--) if(par[u][i]!=par[v][i]){u=par[u][i]; v=par[v][i];}
return par[u][0];
}
void add(ll i){
con[i]++;
if(con[i]==1){
conr[ar[i]]++;
if(conr[ar[i]]==1) answer++;
}
if(con[i]==2){
conr[ar[i]]--;
if(conr[ar[i]]==0) answer--;
}
}
void remove(ll i){
con[i]--;
if(con[i]==1){
conr[ar[i]]++;
if(conr[ar[i]]==1) answer++;
}
if(con[i]==0){
conr[ar[i]]--;
if(conr[ar[i]]==0) answer--;
}
}
int main(){
//buf;
//sieve();
//fact();
ll l,r,i,j,test,ans,m,k,a,b; //string s;
//cin>>test;
test=1;
while(test--){
cin>>n>>m;
for(i=1;i<=n;i++) cin>>ar[i];
i=1;
while(i<n){
cin>>a>>b;
g[a].pb(b); g[b].pb(a);
i++;
}
memset(par,-1,sizeof(par));
dep[0]=-1; dfs(1,0);
//for(i=1;i<=n;i++) cout<<st[i]<<" "<<en[i]<<endl;
block=timer/sqrt(timer);
preLCA();
for(i=0;i<m;i++){
cin>>a>>b;
q[i].i=i;
ll l=lca(a,b);
if(st[a]>st[b]) swap(a,b);
if(l==a||l==b){
q[i].l=st[a]; q[i].r=st[b]; q[i].p=-1;
}
else{
q[i].l=en[a]; q[i].r=st[b]; q[i].p=l;
}
}
block=timer/sqrt(timer);
sort(q,q+m,comp);
ll cl=1,cr=1; add(1);
//for(i=1;i<=timer;i++) cout<<kha[i]<<" ";
//cout<<endl;
for(i=0;i<m;i++){
ll u=q[i].l,v=q[i].r;
//cout<<q[i].i<<" "<<u<<" "<<v<<" "<<q[i].p<<endl;
while(cl<u){
remove(kha[cl]);
//for(j=1;j<=n;j++) cout<<conr[ar[j]]<<" "; cout<<endl;
cl++;
}
//cout<<endl;
while(cl>u){
add(kha[cl+1]);
//for(j=1;j<=n;j++) cout<<conr[ar[j]]<<" "; cout<<endl;
cl--;
}
//cout<<endl;
while(cr>v){
remove(kha[cr]);
//for(j=1;j<=n;j++) cout<<conr[ar[j]]<<" "; cout<<endl;
cr--;
}
//cout<<endl;
while(cr<v){
add(kha[cr+1]);
//for(j=1;j<=n;j++) cout<<conr[ar[j]]<<" "; cout<<endl;
cr++;
}
//cout<<endl;
if(q[i].p!=-1&&con[ar[q[i].p]]==0) out[i]=answer+1;
else out[i]=answer;
//cout<<out[i]<<endl;
}
for(i=0;i<m;i++) cout<<out[i]<<" ";
}
return 0;
}
LypDb2RlZCBieTo6CiAgICAqKkF2aW5hc2ggVGl3YXJ5KioKICAgICoqQkUvMTAyOTgvMjAxNSoqCiAgICAqKlByb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jb25baV0tLTsKICAgIGlmKGNvbltpXT09MSl7IAogICAgICAgIGNvbnJbYXJbaV1dKys7CiAgICAgICAgaWYoY29uclthcltpXV09PTEpIGFuc3dlcisrOwogICAgfQogICAgaWYoY29uW2ldPT0wKXsgCiAgICAgICAgY29uclthcltpXV0tLTsKICAgICAgICBpZihjb25yW2FyW2ldXT09MCkgYW5zd2VyLS07CiAgICB9Cn0KaW50IG1haW4oKXsKICAgIC8vYnVmOyAKICAgIC8vc2lldmUoKTsgCiAgICAvL2ZhY3QoKTsKICAgIGxsIGwscixpLGosdGVzdCxhbnMsbSxrLGEsYjsgLy9zdHJpbmcgczsKICAgIC8vY2luPj50ZXN0OwogICAgdGVzdD0xOwogICAgd2hpbGUodGVzdC0tKXsKICAgICAgICBjaW4+Pm4+Pm07CiAgICAgICAgZm9yKGk9MTtpPD1uO2krKykgY2luPj5hcltpXTsKICAgICAgICBpPTE7CiAgICAgICAgd2hpbGUoaTxuKXsKICAgICAgICAgICAgY2luPj5hPj5iOwogICAgICAgICAgICBnW2FdLnBiKGIpOyBnW2JdLnBiKGEpOwogICAgICAgICAgICBpKys7CiAgICAgICAgfQogICAgICAgIG1lbXNldChwYXIsLTEsc2l6ZW9mKHBhcikpOwogICAgICAgIGRlcFswXT0tMTsgZGZzKDEsMCk7CiAgICAgICAgLy9mb3IoaT0xO2k8PW47aSsrKSBjb3V0PDxzdFtpXTw8IiAiPDxlbltpXTw8ZW5kbDsKICAgICAgICBibG9jaz10aW1lci9zcXJ0KHRpbWVyKTsKICAgICAgICBwcmVMQ0EoKTsKICAgICAgICBmb3IoaT0wO2k8bTtpKyspewogICAgICAgICAgICBjaW4+PmE+PmI7CiAgICAgICAgICAgIHFbaV0uaT1pOwogICAgICAgICAgICBsbCBsPWxjYShhLGIpOwogICAgICAgICAgICBpZihzdFthXT5zdFtiXSkgc3dhcChhLGIpOwogICAgICAgICAgICBpZihsPT1hfHxsPT1iKXsKICAgICAgICAgICAgICAgIHFbaV0ubD1zdFthXTsgcVtpXS5yPXN0W2JdOyBxW2ldLnA9LTE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZXsKICAgICAgICAgICAgICAgIHFbaV0ubD1lblthXTsgcVtpXS5yPXN0W2JdOyBxW2ldLnA9bDsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBibG9jaz10aW1lci9zcXJ0KHRpbWVyKTsKICAgICAgICBzb3J0KHEscSttLGNvbXApOwogICAgICAgIGxsIGNsPTEsY3I9MTsgYWRkKDEpOwogICAgICAgIC8vZm9yKGk9MTtpPD10aW1lcjtpKyspIGNvdXQ8PGtoYVtpXTw8IiAiOwogICAgICAgIC8vY291dDw8ZW5kbDsKICAgICAgICBmb3IoaT0wO2k8bTtpKyspewogICAgICAgICAgICBsbCB1PXFbaV0ubCx2PXFbaV0ucjsKICAgICAgICAgICAgLy9jb3V0PDxxW2ldLmk8PCIgIjw8dTw8IiAiPDx2PDwiICI8PHFbaV0ucDw8ZW5kbDsKICAgICAgICAgICAgd2hpbGUoY2w8dSl7CiAgICAgICAgICAgICAgICByZW1vdmUoa2hhW2NsXSk7CiAgICAgICAgICAgICAgICAvL2ZvcihqPTE7ajw9bjtqKyspIGNvdXQ8PGNvbnJbYXJbal1dPDwiICI7IGNvdXQ8PGVuZGw7CiAgICAgICAgICAgICAgICBjbCsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIC8vY291dDw8ZW5kbDsKICAgICAgICAgICAgd2hpbGUoY2w+dSl7CiAgICAgICAgICAgICAgICBhZGQoa2hhW2NsKzFdKTsKICAgICAgICAgICAgICAgIC8vZm9yKGo9MTtqPD1uO2orKykgY291dDw8Y29uclthcltqXV08PCIgIjsgY291dDw8ZW5kbDsKICAgICAgICAgICAgICAgIGNsLS07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgLy9jb3V0PDxlbmRsOwogICAgICAgICAgICB3aGlsZShjcj52KXsKICAgICAgICAgICAgICAgIHJlbW92ZShraGFbY3JdKTsKICAgICAgICAgICAgICAgIC8vZm9yKGo9MTtqPD1uO2orKykgY291dDw8Y29uclthcltqXV08PCIgIjsgY291dDw8ZW5kbDsKICAgICAgICAgICAgICAgIGNyLS07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgLy9jb3V0PDxlbmRsOwogICAgICAgICAgICB3aGlsZShjcjx2KXsKICAgICAgICAgICAgICAgIGFkZChraGFbY3IrMV0pOwogICAgICAgICAgICAgICAgLy9mb3Ioaj0xO2o8PW47aisrKSBjb3V0PDxjb25yW2FyW2pdXTw8IiAiOyBjb3V0PDxlbmRsOwogICAgICAgICAgICAgICAgY3IrKzsKICAgICAgICAgICAgfQogICAgICAgICAgICAvL2NvdXQ8PGVuZGw7CiAgICAgICAgICAgIGlmKHFbaV0ucCE9LTEmJmNvblthcltxW2ldLnBdXT09MCkgb3V0W2ldPWFuc3dlcisxOwogICAgICAgICAgICBlbHNlIG91dFtpXT1hbnN3ZXI7CiAgICAgICAgICAgIC8vY291dDw8b3V0W2ldPDxlbmRsOwogICAgICAgIH0KICAgICAgICBmb3IoaT0wO2k8bTtpKyspIGNvdXQ8PG91dFtpXTw8IiAiOwogICAgfQogICAgcmV0dXJuIDA7Cn0=