#include <bits/stdc++.h>
using namespace std;
int n, d, a[2007];
const long long mod = 1e9 + 7;
vector<int> e[2007];
long long dp[2007];
bool used[2007];
void Clear() {
  for (int i = 0; i < 2007; i++) e[i].clear();
}
void add(int u, int v) {
  e[u].push_back(v);
  e[v].push_back(u);
}
void dfs(int u, int p, int x) {
  dp[u] = 1;
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i];
    if (v == p) continue;
    if (a[v] > a[x]) continue;
    if (a[v] < max(0, a[x] - d)) continue;
    if (a[v] == a[x] && v < x) continue;
    dfs(v, u, x);
    dp[u] *= dp[v] + 1LL;
    dp[u] %= mod;
  }
}
int main() {
  while (~scanf("%d%d", &d, &n)) {
    Clear();
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i < n; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      add(x, y);
    }
    long long ans = 0;
    memset(used, 0, sizeof(used));
    for (int i = 1; i <= n; i++) {
      dfs(i, -1, i);
      ans += dp[i];
      ans %= mod;
    }
    printf("%lld\n", ans);
  }
}
