#include <bits/stdc++.h>
using namespace std;
const int maxn = 2222;
const long long int mod = 1000000007;
int n, d, root;
long long int w[maxn];
vector<int> g[maxn];
bool vis[maxn][maxn];
long long int dp[maxn];
long long int dfs(int u, int fa) {
  dp[u] = 1;
  for (int i = 0, sz = g[u].size(); i < sz; i++) {
    int v = g[u][i];
    if (v == fa) continue;
    if (!((w[root] <= w[v]) && (w[v] <= w[root] + d))) continue;
    if (vis[root][v]) continue;
    if (w[root] == w[v]) vis[root][v] = vis[v][root] = true;
    int temp = dfs(v, u);
    dp[u] = (dp[u] + temp * dp[u]) % mod;
  }
  return dp[u];
}
int main() {
  cin >> d >> n;
  for (int i = 1; i <= n; i++) cin >> w[i];
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  long long int sum = 0;
  for (int i = 1; i <= n; i++) {
    root = i;
    sum = (sum + dfs(i, i)) % mod;
  }
  cout << sum << endl;
  return 0;
}
