#include <bits/stdc++.h>
using namespace std;
const int mxn = 2e3 + 5;
const long long mod = 1e9 + 7;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
int val[mxn];
long long dp[mxn];
vector<int> adj[mxn];
int d;
void dfs(int u, int p, int x, int root) {
  dp[u] = 1;
  for (auto v : adj[u]) {
    if (v == p || abs(val[v] - x) > d || val[v] < x) continue;
    if (val[v] == x && v > root) continue;
    dfs(v, u, x, root);
    dp[u] = (dp[u] * (dp[v] + 1)) % mod;
    while (dp[u] < 0) dp[u] += mod;
  }
}
int main() {
  int n;
  cin >> d >> n;
  for (int i = 1; i <= n; i++) cin >> val[i];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    memset(dp, 0, sizeof dp);
    dfs(i, i, val[i], i);
    ans = (ans + dp[i] % mod);
    ans %= mod;
    while (ans < 0) ans += mod;
  }
  ans = ans % mod;
  cout << ans << '\n';
  return 0;
}
