#include <bits/stdc++.h>
const int inf = (1ll << 30) - 1;
const int maxn = (int)1e5 + 10;
const int mod = (int)1e9 + 7;
using namespace std;
int n;
vector<int> g[2020];
int a[2020];
pair<int, int> p[2020];
int was[2020];
int u[2020];
int d;
int L;
int T;
long long calc(int v, int pa) {
  long long res = 1;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == pa || was[to] || a[to] - L > d) {
      continue;
    }
    res = (res * (calc(to, v) + 1)) % mod;
  }
  return res;
}
void solve() {
  cin >> d >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    p[i] = make_pair(a[i], i);
  }
  sort(p, p + n);
  for (int x = 1; x < n; x++) {
    int u, v;
    cin >> u >> v;
    g[u - 1].push_back(v - 1);
    g[v - 1].push_back(u - 1);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int v = p[i].second;
    L = p[i].first;
    T++;
    ans += calc(v, -1);
    was[v] = 1;
  }
  cout << ans % mod << "\n";
}
int main() {
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
