#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
const int maxn = 2020;
const long long mod = 1e9 + 7;
int d, n;
bool viz[maxn];
vector<int> g[maxn];
long long f[maxn];
int a[maxn];
void dfs(int at, int root) {
  viz[at] = true;
  f[at] = 1;
  for (int to : g[at]) {
    if (viz[to]) continue;
    if (a[to] < a[root]) continue;
    if (a[to] > a[root] + d) continue;
    if (a[to] == a[root] && to < root) continue;
    dfs(to, root);
    f[at] *= (1 + f[to]);
    f[at] %= mod;
    f[at] += mod;
    f[at] %= mod;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> d >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    memset(viz, false, sizeof viz);
    memset(f, 0, sizeof f);
    dfs(i, i);
    ans += f[i];
    ans %= mod;
    ans += mod;
    ans %= mod;
  }
  ans %= mod;
  ans += mod;
  ans %= mod;
  cout << ans << endl;
  return 0;
}
