#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
const int N = 2005;
vector<int> g[N];
int mas[N];
bool used[N];
long long ans = 0;
long long dfs(int v, int mn, int mx, int p = -1) {
  if (mas[v] == mn && used[v]) return 0;
  long long r = 1;
  for (int i = 0; i < (int)g[v].size(); ++i)
    if (p != g[v][i] && mas[g[v][i]] <= mx && mas[g[v][i]] >= mn) {
      long long d = dfs(g[v][i], mn, mx, v);
      r = (d * 1ll * r + r) % mod;
    }
  return r;
}
int main() {
  ios::sync_with_stdio(0);
  int d, n;
  cin >> d >> n;
  for (int i = 0; i < n; ++i) cin >> mas[i];
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ans = 0;
  for (int mn = 1; mn <= 2000; ++mn) {
    memset(used, 0, sizeof used);
    for (int i = 0; i < n; ++i)
      if (mas[i] == mn) {
        ans += dfs(i, mn, mn + d);
        ans %= mod;
        used[i] = 1;
      }
  }
  cout << ans << "\n";
  return 0;
}
