#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
struct node {
  int v;
  int nxt;
} e[100010];
long long dp[2010], ans;
int n, h[2010], cnt, val[2010], d;
void add(int u, int v) {
  e[++cnt].v = v;
  e[cnt].nxt = h[u];
  h[u] = cnt;
}
void dfs(int u, int fa, int ma, int rt) {
  dp[u] = 1;
  for (int i = h[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa) continue;
    if (val[v] > ma || ma - val[v] > d) continue;
    if (val[v] == ma && v > rt) continue;
    dfs(v, u, ma, rt);
    dp[u] = (dp[u] * (dp[v] + 1) % mod) % mod;
  }
}
int main() {
  scanf("%d%d", &d, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &val[i]);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  for (int i = 1; i <= n; i++) {
    memset(dp, 0, sizeof(dp));
    dfs(i, 0, val[i], i);
    ans = (ans + dp[i]) % mod;
  }
  printf("%lld", ans % mod);
}
