#include <bits/stdc++.h>
using namespace std;
int n, d;
int a[2005];
vector<int> edge[2005];
void read() {
  cin >> d >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int x, y;
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
}
long long dfs(int now, int p, int rt, int mx) {
  if (mx - a[now] > d || a[now] > mx || (a[now] == mx && p != -1 && now < rt))
    return 0;
  long long res = 1;
  for (int i = 0; i < edge[now].size(); i++) {
    int temp = edge[now][i];
    if (temp != p) res = res * (dfs(temp, now, rt, mx) + 1) % 1000000007;
  }
  return res;
}
void work() {
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans = (ans + dfs(i, -1, i, a[i])) % 1000000007;
  cout << ans << endl;
}
int main() {
  read();
  work();
}
