#include <bits/stdc++.h>
using namespace std;
const int MAX = 2005, MOD = 1e9 + 7;
int n, d, C[MAX];
vector<int> G[MAX];
long long dfs(int nod, int p, int val, int ni) {
  if (C[nod] < val || C[nod] > val + d || (C[nod] == val && nod < ni)) return 1;
  long long ans = 1;
  for (int i = 0; i < G[nod].size(); i++) {
    int newn = G[nod][i];
    if (newn == p) continue;
    ans = (ans * (dfs(newn, nod, val, ni))) % MOD;
  }
  return ans + 1;
}
int main() {
  scanf("%d%d", &d, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &C[i]);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  long long sol = 0;
  for (int i = 1; i <= n; i++) {
    sol = (sol + dfs(i, -1, C[i], i)) % MOD;
    sol = (sol - 1 + MOD) % MOD;
  }
  printf("%I64d\n", sol);
  return 0;
}
