#include <bits/stdc++.h>
using namespace std;
const int N = 2001;
const int md = 1e9 + 7;
int d, n, mx, sz, ans, g, c[N];
vector<int> a[N];
int dp[N];
bool used[N];
void dfs(int v, int p = 0) {
  if (c[v] < mx || c[v] > c[g]) return;
  if (c[v] == c[g] && v > g) return;
  dp[v] = 1;
  for (int i = 0; i < a[v].size(); ++i) {
    int to = a[v][i];
    if (to == p) continue;
    dfs(to, v);
    dp[v] = (dp[v] * 1ll * (dp[to] + 1)) % md;
  }
}
int main() {
  cin >> d >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> c[i];
  }
  int x, y;
  for (int i = 1; i < n; ++i) {
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  for (int i = 1; i <= n; ++i) {
    memset(dp, 0, sizeof(dp));
    if (used[c[i]]) continue;
    mx = c[i] - d;
    g = i;
    dfs(i);
    ans += dp[i];
    if (ans >= md) ans -= md;
  }
  cout << ans;
}
