#include <bits/stdc++.h>
using namespace std;
const int Max = 2e3 + 10;
const int Mod = 1e9 + 7;
const long long int Inf = 1LL << 62;
int F[Max];
int ar[Max];
vector<int> G[Max];
int dfs(int u, int par, int d) {
  F[u] = 1;
  for (int v : G[u])
    if (F[v] == 0) {
      if (ar[v] < ar[par] || ar[v] > ar[par] + d) {
        continue;
      }
      if (ar[v] == ar[par] && v < par) {
        continue;
      }
      F[u] = (1LL * (F[u] % Mod) * ((dfs(v, par, d) + 1) % Mod) % Mod) % Mod;
    }
  return F[u];
}
int solve(int src, int d) {
  memset(F, 0, sizeof F);
  return dfs(src, src, d);
}
int main() {
  int d, n, u, v, ans = 0;
  scanf("%d %d", &d, &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
  }
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    ans = (ans % Mod + solve(i, d) % Mod) % Mod;
  }
  printf("%d\n", ans);
  return 0;
}
