#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
const long long mod = 1000000007;
int d, n;
vector<int> g[maxn];
long long dp[maxn], a[maxn];
int uroot;
void dfs(int node, int root) {
  dp[node] = 1LL;
  for (int i : g[node]) {
    if (i == root) continue;
    if (a[i] == a[uroot] && (i < uroot)) continue;
    if (a[i] >= a[uroot] && a[i] <= a[uroot] + d) {
      dfs(i, node);
      dp[node] *= (dp[i] + 1LL);
      dp[node] %= mod;
    }
  }
}
int main() {
  cin >> d >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int u, v;
  for (int i = 1; i <= n - 1; i++) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  long long result = 0LL;
  for (int i = 1; i <= n; i++) {
    memset(dp, 0, sizeof(dp));
    uroot = i;
    dfs(i, i);
    result += dp[i];
    result %= mod;
  }
  cout << result;
}
