#include <bits/stdc++.h>
using namespace std;
vector<int> G[2005];
long long f[2005];
int vis[2005], a[2005], n, d;
void dfs(int u, int root) {
  vis[u] = 1;
  f[u] = 1;
  for (int i = 0; i < (int)G[u].size(); i++) {
    int v = G[u][i];
    if (vis[v]) continue;
    if (a[v] < a[root] || a[v] > a[root] + d) continue;
    if (a[v] == a[root] && v < root) continue;
    dfs(v, root);
    f[u] = (f[u] * (f[v] + 1)) % 1000000007;
  }
}
int main() {
  int u, v;
  cin >> d >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    memset(vis, 0, sizeof(vis));
    dfs(i, i);
    ans = (ans + f[i]) % 1000000007;
  }
  cout << ans << endl;
  return 0;
}
