#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::max;
using std::min;
using std::multiset;
using std::pair;
using std::priority_queue;
using std::queue;
using std::sort;
using std::vector;
const int maxN = 100000 + 233;
const int maxC = 100000 + 233;
const int maxQ = 100000 + 233;
const int NODE = 6000000 + 233;
int n, m, sz[maxN], col[maxN];
vector<int> G[maxN];
vector<int> Q[maxN];
int qv[maxQ], qk[maxQ], qa[maxQ];
void dfs_size(int u, int fa) {
  if (u != 1) {
    for (vector<int>::iterator it = G[u].begin(); it != G[u].end(); ++it) {
      if (*it == fa) {
        G[u].erase(it);
        break;
      }
    }
  }
  sz[u] = 1;
  for (int v : G[u]) {
    dfs_size(v, u);
    sz[u] += sz[v];
  }
}
bool cmp(int x, int y) { return sz[x] > sz[y]; }
void initialize() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &col[i]);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &qv[i], &qk[i]);
    qa[i] = -1;
    Q[qv[i]].push_back(i);
  }
  dfs_size(1, -1);
  for (int u = 1; u <= n; ++u) std::sort(G[u].begin(), G[u].end(), cmp);
}
namespace SegmentTree {
int stk[NODE], stk_top = 0;
struct Node;
Node *nil;
struct Node {
  int s;
  Node *lson, *rson;
  Node(int s = 0) : s(s), lson(nil), rson(nil) {}
  void print() {
    printf("%lld : size = %d, ch = {%lld, %lld}\n", this - nil, s, lson - nil,
           rson - nil);
  }
} nodes[NODE];
void init() {
  for (int i = 1; i < NODE; ++i) stk[i] = i;
  stk_top = NODE - 1;
  nil = nodes;
  *nil = Node();
}
Node *alloc() {
  nodes[stk[stk_top]] = Node();
  return &nodes[stk[stk_top--]];
}
void disp(Node *o) { stk[++stk_top] = o - nil; }
vector<pair<int, int> > changes;
void dig(Node *o, int L, int R) {
  if (L == R) {
    changes.push_back(pair<int, int>(0, o->s));
  } else {
    int M = (L + R) >> 1;
    if (o->lson->s) dig(o->lson, L, M);
    if (o->rson->s) dig(o->rson, M + 1, R);
  }
}
Node *merge(Node *x, Node *y, int L, int R) {
  if (y == nil)
    return x;
  else if (x == nil) {
    dig(y, L, R);
    return y;
  } else {
    Node *o = alloc();
    o->s = x->s + y->s;
    if (L == R) {
      changes.push_back(pair<int, int>(x->s, o->s));
    } else {
      int M = (L + R) >> 1;
      o->lson = merge(x->lson, y->lson, L, M);
      o->rson = merge(x->rson, y->rson, M + 1, R);
    }
    disp(x);
    disp(y);
    return o;
  }
}
int post_sum(Node *o, int L, int R, int pos) {
  int ret = 0;
  while (o != nil && L < R) {
    int M = (L + R) >> 1;
    if (pos <= M)
      ret += o->rson->s, R = M, o = o->lson;
    else
      L = M + 1, o = o->rson;
  }
  if (L == R) ret += o->s;
  return ret;
}
void modify(Node *&root, int L, int R, int p, int v) {
  if (root == nil) root = alloc();
  Node *o = root;
  while (L < R) {
    o->s += v;
    int M = (L + R) >> 1;
    if (p <= M) {
      R = M;
      if (o->lson == nil) o->lson = alloc();
      o = o->lson;
    } else {
      L = M + 1;
      if (o->rson == nil) o->rson = alloc();
      o = o->rson;
    }
  }
  changes.push_back(pair<int, int>(o->s, o->s + v));
  o->s += v;
}
multiset<int> dfs(Node *o, int L, int R) {
  multiset<int> S;
  S.clear();
  if (o == nil)
    return S;
  else {
    int M = (L + R) >> 1;
    multiset<int> T;
    T = dfs(o->lson, L, M);
    S.insert(T.begin(), T.end());
    T = dfs(o->rson, M + 1, R);
    S.insert(T.begin(), T.end());
    if (L == R)
      for (int i = 0; i < o->s; ++i) S.insert(L);
    return S;
  }
}
}  // namespace SegmentTree
using namespace SegmentTree;
typedef pair<Node *, Node *> pnn;
pnn dfs(int u) {
  Node *rt = nil, *ct = nil;
  vector<pair<int, int> > mods;
  changes.clear();
  int cnt = 0;
  for (int v : G[u]) {
    if (++cnt == 1) {
      pnn np = dfs(v);
      rt = np.first;
      ct = np.second;
    } else {
      pnn np = dfs(v);
      changes.clear();
      ct = merge(ct, np.second, 1, maxC);
      mods.insert(mods.end(), changes.begin(), changes.end());
    }
  }
  changes.clear();
  modify(ct, 1, maxN, col[u], 1);
  mods.insert(mods.end(), changes.begin(), changes.end());
  for (pair<int, int> &p : mods)
    if (p.first != p.second) {
      if (p.first) modify(rt, 1, maxN, p.first, -1);
      if (p.second) modify(rt, 1, maxN, p.second, +1);
    }
  for (int i : Q[u]) {
    qa[i] = post_sum(rt, 1, maxN, qk[i]);
  }
  return pnn(rt, ct);
}
void solve() {
  init();
  dfs(1);
}
void print_ans() {
  for (int i = 1; i <= m; ++i) printf("%d\n", qa[i]);
}
int main() {
  initialize();
  solve();
  print_ans();
  return 0;
}
