#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const int mod = 1e9 + 7;
int n, k, son[N], ed[N * 2], ne[N * 2], b[N], pos, d, x, y, l;
bool f[N];
long long dp[N], ans;
struct node {
  int i, da;
} a[N];
bool cmp(node a, node b) { return a.da > b.da; }
void dfs(int x) {
  f[x] = 1;
  dp[x] = 1;
  for (int l = son[x]; l; l = ne[l]) {
    int y = ed[l];
    if (f[y] || b[y] < pos || a[pos].da - a[b[y]].da > d) continue;
    dfs(y);
    dp[x] *= (dp[y] + 1);
    dp[x] %= mod;
  }
}
int main() {
  scanf("%d%d", &d, &n);
  for (int i = (1); i < (n + 1); i++) {
    scanf("%d", &a[i].da);
    a[i].i = i;
  }
  for (int i = (1); i < (n); i++) {
    scanf("%d%d", &x, &y);
    l++;
    ne[l] = son[x];
    son[x] = l;
    ed[l] = y;
    l++;
    ne[l] = son[y];
    son[y] = l;
    ed[l] = x;
  }
  sort(a + 1, a + n + 1, cmp);
  for (int i = (1); i < (n + 1); i++) b[a[i].i] = i;
  for (int i = (1); i < (n + 1); i++) {
    memset(dp, 0, sizeof(dp));
    memset(f, 0, sizeof(f));
    pos = i;
    dfs(a[i].i);
    ans += dp[a[i].i];
    ans %= mod;
  }
  printf("%lld", ans);
  return 0;
}
