#include <bits/stdc++.h>
using namespace std;
const long MAX_N = 2e3 + 1;
const long long MOD = 1e9 + 7;
long d, n;
long w[MAX_N];
vector<long> g[MAX_N];
long long dp[MAX_N];
long long ans;
void add_edge(long a, long b) {
  g[a].push_back(b);
  g[b].push_back(a);
}
void dfs(long a, long p, long r) {
  dp[a] = 1;
  for (size_t i = 0; i < g[a].size(); i++) {
    long b = g[a][i];
    if (b == p) continue;
    if (w[b] - w[r] > d) continue;
    if (w[r] > w[b]) continue;
    if (w[r] == w[b] && r > b) continue;
    dfs(b, a, r);
    dp[a] *= (dp[b] + 1ll);
    dp[a] %= MOD;
  }
}
int main() {
  cin >> d >> n;
  for (long i = 1; i <= n; i++) {
    cin >> w[i];
  }
  for (long i = 1; i < n; i++) {
    long a, b;
    cin >> a >> b;
    add_edge(a, b);
  }
  ans = 0;
  for (long i = 1; i <= n; i++) {
    dfs(i, -1, i);
    ans += dp[i];
    ans %= MOD;
  }
  cout << ans;
  return 0;
}
