#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
int n, d, arr[2001], mx;
long long ans, dp[2001][2];
vector<int> adj[2001];
void DFS(int u = 1, int p = -1) {
  for (int i : adj[u])
    if (i != p) DFS(i, u);
  dp[u][arr[u] == mx] = 1;
  dp[u][0] *= (arr[u] >= (mx - d)) && (arr[u] <= mx);
  dp[u][1] *= (arr[u] >= (mx - d)) && (arr[u] <= mx);
  for (int i : adj[u]) {
    if (i == p) continue;
    dp[u][1] =
        ((dp[u][0] * dp[i][1]) % 1000000007 +
         (dp[u][1] * ((dp[i][0] + dp[i][1] + 1) % 1000000007)) % 1000000007) %
        1000000007;
    dp[u][0] = (dp[u][0] * (dp[i][0] + 1)) % 1000000007;
  }
  ans += dp[u][1];
  if (ans >= 1000000007) ans -= 1000000007;
}
int main() {
  scanf("%d %d", &d, &n);
  for (int i = 1; i <= n; i++) scanf("%d", arr + i);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (mx = 1; mx <= 2000; mx++) {
    memset(dp, 0, sizeof dp);
    DFS();
  }
  printf("%lld", ans);
  return 0;
}
