#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int d, n, a[2000];
pair<int, int> arr[2000];
vector<int> adj[2000];
bool disabled[2000];
long long dfs(int u, int val, int p = -1) {
  if (disabled[u] || val - a[u] > d) return 0;
  long long s = 1;
  for (int v : adj[u])
    if (v != p) s = (s * (1 + dfs(v, val, u))) % MOD;
  return s;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> d >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    arr[i].first = a[i];
    arr[i].second = i;
  }
  for (int i = 0, u, v; i < n - 1; i++) {
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  sort(arr, arr + n);
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    int u = arr[i].second;
    ans = (ans + dfs(u, a[u])) % MOD;
    disabled[u] = true;
  }
  cout << ans << '\n';
  return 0;
}
