#include <bits/stdc++.h>
using namespace std;
vector<int> v[10000];
int vi[10000] = {0}, ar[10000], d;
long long f[10000] = {0};
long long dfs(int u, int r) {
  vi[u] = 1;
  int j, l = v[u].size();
  for (j = 0; j < l; j++) {
    if (!vi[v[u][j]]) {
      int ve = v[u][j];
      if (ar[ve] >= ar[r] && ar[ve] <= ar[r] + d) {
        if (ar[ve] == ar[r] && ve > r) continue;
        dfs(ve, r), f[u] = (f[u] * (f[ve] + 1)) % 1000000007LL;
      }
    }
  }
  return f[u];
}
int main() {
  int n, a, b, j, i;
  long long an = 0;
  cin >> d >> n;
  for (i = 1; i < n + 1; i++) scanf("%d", &ar[i]);
  for (i = 1; i < n; i++)
    scanf("%d%d", &a, &b), v[a].push_back(b), v[b].push_back(a);
  for (i = 1; i < n + 1; i++) {
    for (j = 1; j < n + 1; j++) {
      vi[j] = 0;
      f[j] = 1;
    }
    an = (an + dfs(i, i)) % 1000000007LL;
  }
  cout << an;
  return 0;
}
