#include <bits/stdc++.h>
using namespace std;
vector<int> V[2222];
int val[2222];
long long dp[2222];
int d;
bool vis[2222];
void dfs(int u, int fa) {
  int sz = V[u].size();
  vis[u] = true;
  for (int i = 0; i < sz; i++) {
    int v = V[u][i];
    if (vis[v]) continue;
    if ((val[v] > val[fa] && val[v] <= val[fa] + d) ||
        (val[v] == val[fa] && v > fa)) {
      dfs(v, fa);
      dp[u] = (dp[u] * (dp[v] + 1)) % 1000000007;
    }
  }
}
int main() {
  int n;
  while (cin >> d >> n) {
    for (int i = 1; i <= n; i++) V[i].clear();
    for (int i = 1; i <= n; i++) cin >> val[i];
    int a, b;
    for (int i = 0; i < n - 1; i++) {
      cin >> a >> b;
      V[a].push_back(b);
      V[b].push_back(a);
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      memset(vis, false, sizeof(vis));
      for (int j = 1; j <= n; j++) dp[j] = 1;
      dfs(i, i);
      ans = (ans + dp[i]) % 1000000007;
    }
    cout << ans << endl;
  }
  return 0;
}
