#include <bits/stdc++.h>
using namespace std;
const bool DEBUG_FLAG = 0;
int GetInt() {
  register int aa = 0, bb = 1;
  register char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  ch == '-' ? aa = 0, bb = -1 : aa = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9')
    aa = (aa << 1) + (aa << 3) + ch - '0';
  return bb == 1 ? aa : -aa;
}
const int N = 2010;
const int M = 4010;
const int Mod = 1000000007;
int d, n, a[N], f[N];
int Et[M], Ep[M], Last[M], En;
void insert(int f, int t) {
  Et[++En] = t;
  Ep[En] = Last[f];
  Last[f] = En;
  if (En & 1) insert(t, f);
}
int Dfs(int x, int p, int Root) {
  if (a[x] > a[Root] || a[x] < a[Root] - d) return 0;
  if (x > Root && a[Root] == a[x]) return 0;
  register int ret = 1, i;
  for (i = Last[x]; i; i = Ep[i]) {
    if (Et[i] == p) continue;
    ret = 1ll * ret * (Dfs(Et[i], x, Root) + 1) % Mod;
  }
  return ret;
}
int main() {
  register int i, u, v, Ans = 0;
  d = GetInt();
  n = GetInt();
  for (i = 1; i <= n; i++) a[i] = GetInt();
  for (i = 1; i < n; i++) {
    u = GetInt();
    v = GetInt();
    insert(u, v);
  }
  for (i = 1; i <= n; i++) {
    u = Dfs(i, 0, i);
    if (DEBUG_FLAG) printf("%d\n", u);
    (Ans += u) %= Mod;
  }
  printf("%d", Ans);
}
