#include <bits/stdc++.h>
using namespace std;
vector<long long int> edges[2005];
long long int a[2005];
bool visited[2005];
bool done[2005];
long long int M = 1000000007;
long long int dfs(long long int curr) {
  visited[curr] = true;
  long long int ret = 1, i, temp;
  for (i = 0; i < edges[curr].size(); i++) {
    if (!visited[edges[curr][i]]) {
      temp = dfs(edges[curr][i]);
      ret = ((ret % M) * (temp % M)) % M;
    }
  }
  ret = (ret + 1) % M;
  return ret % M;
}
int main() {
  ios::sync_with_stdio(false);
  memset(done, 0, sizeof(done));
  long long int d, n, i, j;
  cin >> d >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long int u, v;
  for (i = 0; i < n - 1; i++) {
    cin >> u >> v;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  long long int ans = 0, tans;
  for (i = 1; i <= n; i++) {
    memset(visited, 0, sizeof(visited));
    for (j = 1; j <= n; j++) {
      if (a[j] > a[i]) visited[j] = true;
      if (a[j] + d < a[i]) visited[j] = true;
      if (a[j] == a[i] && done[j] == true) visited[j] = true;
    }
    tans = dfs(i);
    tans = (tans - 1 + M) % M;
    ans = ((ans % M) + (tans % M)) % M;
    done[i] = true;
  }
  ans = ans % M;
  cout << ans << '\n';
  return 0;
}
