#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int pl = 1e6;
double rast(int x1, int y1, int x2, int y2) {
  return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
void add_self(long long &a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
}
void mul_self(long long &a, long long b) {
  a *= b;
  if (a >= mod) a %= mod;
}
int a[2005];
int d, n;
vector<int> g[2005];
bool used[2005];
long long dp[2005];
void dfs(int v, int root) {
  used[v] = true;
  dp[v] = 1;
  for (int to : g[v]) {
    if (used[to]) continue;
    if (a[to] < a[root] || a[to] > a[root] + d) continue;
    if (a[to] == a[root] && to < root) continue;
    dfs(to, root);
    mul_self(dp[v], dp[to] + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> d >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    g[l].push_back(r);
    g[r].push_back(l);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) dp[j] = 0, used[j] = false;
    dfs(i, i);
    add_self(ans, dp[i]);
  }
  cout << ans;
}
