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