#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
vector<int> a(2010);
long long int dp[2010];
bool vis[2010];
int d, n;
vector<long long int> adj[2010];
void dfs(int i, int start) {
  if (vis[i]) return;
  vis[i] = 1;
  dp[i] = 1;
  for (auto j : adj[i]) {
    if (vis[j]) continue;
    if (a[j] < a[start] or a[j] > a[start] + d) continue;
    if (a[j] == a[start] and j < start) continue;
    dfs(j, start);
    dp[i] = (dp[i] * (dp[j] + 1)) % mod;
  }
}
int main() {
  cin >> d >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1, x, y; i < n; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dp[j] = 0;
      vis[j] = 0;
    }
    dfs(i, i);
    ans = (ans + dp[i]) % mod;
  }
  cout << ans << endl;
}
