#include <bits/stdc++.h>
using namespace std;
const int maxn = 2020;
const int MOd = 1e9 + 7;
int a, d, dad[maxn], sz[maxn];
int ar[maxn];
vector<int> w[maxn];
long long dfs(int n, int back, int s) {
  long long ret = 1;
  int c = 0;
  for (int i = 0; i < w[n].size(); i++)
    if (w[n][i] != back && ((ar[w[n][i]] <= ar[s] + d && ar[s] < ar[w[n][i]]) ||
                            (ar[w[n][i]] == ar[s] && w[n][i] > s)))
      ret *= 1 + dfs(w[n][i], n, s), ret %= MOd, c = 1;
  return ret;
}
int main() {
  scanf("%d %d", &d, &a);
  for (int i = 1; i <= a; i++) scanf("%d", &ar[i]);
  for (int i = 1, j, k; i < a; i++)
    scanf("%d %d", &j, &k), w[j].push_back(k), w[k].push_back(j);
  long long ans = 0;
  for (int i = 1; i <= a; i++) ans += dfs(i, 0, i);
  cout << ans % MOd << endl;
  return 0;
}
