#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long long int maxn = 2e3 + 1;
vector<long long int> adj[maxn];
vector<long long int> a;
vector<long long int> f;
long long int d, n;
void dfs(long long int s, long long int p, long long int root) {
  long long int val = 1;
  for (auto to : adj[s]) {
    if (to == p) continue;
    if ((a[to] == a[root]) && (to < root)) continue;
    if (a[to] >= a[root] && a[to] - a[root] <= d) dfs(to, s, root);
    val = (val * (f[to] + 1)) % MOD;
  }
  f[s] = val;
}
void solve() {
  cin >> d >> n;
  a.resize(n + 1);
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long int i = 1; i <= n - 1; i++) {
    long long int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    f.resize(n + 1, 0);
    dfs(i, -1, i);
    ans = (ans + f[i]) % MOD;
    f.clear();
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
