#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long dp[2009];
int a[2009];
int n, d;
vector<int> g[2009];
vector<int> t[2009];
void norm(long long &num) {
  if (num >= mod) num %= mod;
  while (num < 0) num += mod;
}
void dfs(int u, int p, int root) {
  dp[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v == p) continue;
    if (a[v] < a[root] || a[v] > a[root] + d) continue;
    if (a[v] == a[root] && v < root) continue;
    dfs(v, u, root);
    dp[u] = (1LL * dp[u] * (1 + dp[v]));
    norm(dp[u]);
  }
}
void makeTree(int u, int p, int root) {
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v == p) continue;
    if (a[v] >= a[root] && a[v] <= a[root] + d) {
      if (a[v] == a[root] && v < root) continue;
      t[u].push_back(v);
      t[v].push_back(u);
      makeTree(v, u, root);
    }
  }
}
int main() {
  scanf("%d%d", &d, &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int k = 0; k <= n; k++) {
      t[k].clear();
      dp[k] = 0;
    }
    dfs(i, -1, i);
    ans += dp[i];
    norm(ans);
  }
  printf("%I64d\n", ans % mod);
  return 0;
}
