#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MAX_COUNT = 2e3 + 1;
const int MOD = 1e9 + 7;
int n;
int d;
vector<int> g[MAX_COUNT];
int val[MAX_COUNT];
long long ans;
long long dfs(int u, int p, int root) {
  if (val[u] < val[root]) return 0;
  if (val[u] > val[root] + d) return 0;
  if (val[u] == val[root] && u < root) return 0;
  long long res = 1;
  for (int v : g[u]) {
    if (v == p) continue;
    res = (res * (dfs(v, u, root) + 1)) % MOD;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> d >> n;
  for (int i = 1; i < (n + 1); ++i) {
    cin >> val[i];
  }
  for (int i = 0; i < (n - 1); ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i < (n + 1); ++i) {
    ans = (ans + dfs(i, -1, i)) % MOD;
    ;
  }
  cout << ans << endl;
  return 0;
}
