#include <bits/stdc++.h>
using namespace std;
const int N = 3007;
const int mod = (int)1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int n, d;
vector<int> g[N];
int a[N], f[N];
bool mark[N];
int root, value;
void solve(int v) {
  mark[v] = 1;
  f[v] = 1;
  for (int u : g[v]) {
    if (mark[u]) continue;
    if (a[u] < value || a[u] > value + d) continue;
    if (a[u] == value && (u < root)) continue;
    solve(u);
    f[v] = (1LL * f[v] * (f[u] + 1)) % mod;
  }
}
int main() {
  cin >> d >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    memset(mark, 0, sizeof(mark));
    memset(f, 0, sizeof(f));
    value = a[i];
    root = i;
    solve(i);
    add(ans, f[i]);
  }
  cout << ans << endl;
  return 0;
}
