#include <bits/stdc++.h>
using namespace std;
const long long M = 2e5 + 10, oo = 1e9 + 7;
vector<long long> adj[2020];
long long ara[2020], vis[2020], d, n;
long long dfs(long long s, long long u) {
  long long ans = 1;
  vis[u] = 1;
  for (long long i = 0; i < adj[u].size(); i++) {
    long long v = adj[u][i];
    if (!vis[v]) {
      if (ara[s] == ara[v] && v < s) continue;
      if (ara[s] > ara[v] || ara[v] - ara[s] > d) continue;
      ans = (ans * (dfs(s, v) + 1)) % oo;
    }
  }
  return ans % oo;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> d >> n;
  for (int i = 1; i <= n; i++) cin >> ara[i];
  for (int i = 0, u, v; i < n - 1; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int i = 1; i <= n; i++) vis[i] = 0;
    ans = (ans + dfs(i, i)) % oo;
  }
  cout << ans << endl;
  return 0;
}
