#include <bits/stdc++.h>
using namespace std;
int n, d;
int a[2000];
pair<int, int> b[2000];
vector<int> e[2000];
bool used[2000];
bool tused[2000];
long long int ans = 0;
long long int Abs(long long int x) {
  if (x < 0)
    return x * -1;
  else
    return x;
}
long long int dfs(int x, int y) {
  tused[x] = true;
  long long int ret = 1;
  bool ok = false;
  for (int i = 0; i < e[x].size(); i++) {
    if (used[e[x][i]]) continue;
    if (tused[e[x][i]]) continue;
    if (Abs(a[e[x][i]] - y) > d) continue;
    ok = true;
    ret *= (dfs(e[x][i], y) + 1);
    ret %= 1000000007;
  }
  if (!ok)
    return 1;
  else
    return ret % 1000000007;
}
int main() {
  cin >> d >> n;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) {
    b[i].first = a[i];
    b[i].second = i;
  }
  for (int i = 0; i < n - 1; i++) {
    int p, q;
    scanf("%d%d", &p, &q);
    p--;
    q--;
    e[p].push_back(q);
    e[q].push_back(p);
  }
  sort(b, b + n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) tused[j] = false;
    ans += dfs(b[i].second, b[i].first);
    ans %= 1000000007;
    used[b[i].second] = true;
  }
  cout << ans % 1000000007 << endl;
}
