#include <bits/stdc++.h>
using namespace std;
const long long int maxN = 3e3 + 10;
long long int mn[maxN], mx[maxN], a[maxN];
vector<long long int> g[maxN];
long long int n, m, d, ans, mod = 1e9 + 7;
void input() {
  cin >> d >> n;
  for (long long int i = 1; i <= n; i++) cin >> a[i];
  for (long long int i = 1; i < n; i++) {
    long long int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
}
bool valid(long long int u, long long int xy, long long int z) {
  if (a[u] - xy <= d)
    if ((u > z && a[u] == xy) || a[u] > xy) return true;
  return false;
}
long long int dfs(long long int v, long long int p, long long int xy,
                  long long int z) {
  long long int val = 1;
  for (long long int i = 0; i < g[v].size(); i++) {
    long long int u = g[v][i];
    if (p == u) continue;
    if (valid(u, xy, z)) val = ((dfs(u, v, xy, z) + 1) * val) % mod;
  }
  return val;
}
int main() {
  input();
  for (long long int i = 1; i <= n; i++) {
    ans += dfs(i, 0, a[i], i), ans %= mod;
  }
  cout << ans << endl;
}
