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