#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int d, n;
int a[maxn];
vector<int> g[maxn];
bool vis[maxn];
long long dp[maxn];
void dfs(int u, int root) {
  vis[u] = true;
  dp[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (vis[v] == false) {
      if (a[v] < a[root] || a[v] > a[root] + d)
        continue;
      else if (a[v] == a[root] && v < root)
        continue;
      else {
        dfs(v, root);
        dp[u] *= (dp[v] + 1);
        dp[u] %= mod;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> d >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    memset(vis, false, sizeof(vis));
    dfs(i, i);
    ans += dp[i];
    ans %= mod;
  }
  cout << ans << endl;
}
