#include <bits/stdc++.h>
using namespace std;
const long long int block = 448;
vector<long long int> adj[100005];
long long int st[100005], en[100005], timer;
pair<pair<long long int, long long int>, long long int> qry[200005];
long long int cnt[100005];
long long int avb[100005];
long long int an[100005];
pair<long long int, long long int> a[100005];
long long int n, q, ans, k;
inline void dfs(long long int x, long long int pr) {
  st[x] = ++timer;
  for (auto i : adj[x])
    if (i != pr) dfs(i, x);
  en[x] = timer;
}
inline bool cmp_clr(pair<long long int, long long int> a,
                    pair<long long int, long long int> b) {
  return st[a.second] < st[b.second];
}
inline bool cmp(pair<pair<long long int, long long int>, long long int> a,
                pair<pair<long long int, long long int>, long long int> b) {
  long long int l1 = st[a.first.first], r1 = en[a.first.first];
  long long int l2 = st[b.first.first], r2 = en[b.first.first];
  if (l1 / block == l2 / block) return r1 < r2;
  return l1 / block < l2 / block;
}
inline void add(pair<long long int, long long int> val) {
  cnt[val.first]++;
  avb[cnt[val.first] - 1]--;
}
inline void remove(pair<long long int, long long int> val) {
  if (cnt[val.first] == 0) return;
  cnt[val.first]--;
  avb[cnt[val.first]]++;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> q;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  for (long long int i = 1; i < n; i++) {
    long long int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 1);
  sort(a + 1, a + 1 + n, cmp_clr);
  for (long long int i = 1; i <= q; i++) {
    long long int x, y;
    cin >> x >> y;
    qry[i].first.first = x, qry[i].first.second = y, qry[i].second = i;
  }
  sort(qry + 1, qry + 1 + q, cmp);
  long long int cur_l = 1, cur_r = 0;
  for (long long int i = 1; i <= q; i++) {
    long long int l = st[qry[i].first.first], r = en[qry[i].first.first];
    k = qry[i].first.second;
    while (cur_r < r) {
      cur_r++;
      add(a[cur_r]);
    }
    while (cur_r > r) {
      remove(a[cur_r]);
      cur_r--;
    }
    while (cur_l > l) {
      cur_l--;
      add(a[cur_l]);
    }
    while (cur_l < l) {
      remove(a[cur_l]);
      cur_l++;
    }
    an[qry[i].second] = avb[100004] - avb[k - 1];
  }
  for (long long int i = 1; i <= q; i++) cout << an[i] << '\n';
}
