#include <bits/stdc++.h>
using namespace std;
int const maxn = 2005;
int const mod = 1000000007;
int arr[maxn];
vector<int> adj[maxn];
int dp[maxn];
int ans = 0, d;
void dfs(int index, int fa, int mmax, int node) {
  for (int i = 0; i < adj[index].size(); i++) {
    int to = adj[index][i];
    if (to != fa && (mmax > arr[to] || (mmax == arr[to] && node < to)) &&
        (mmax - arr[to]) <= d) {
      dp[to] = dp[index];
      dfs(to, index, mmax, node);
      dp[index] += dp[to];
      dp[index] %= mod;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, a, b;
  cin >> d >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i < n; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    memset(dp, 0, sizeof(dp));
    dp[i] = 1;
    dfs(i, -1, arr[i], i);
    ans += dp[i];
    ans %= mod;
  }
  cout << ans << '\n';
  return 0;
}
