#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
long long INF = 1000000000007;
long long MOD = 1000000007;
long long ans = 0;
bool vis[20005] = {false};
vector<int> adj[20005];
int c[20005];
long long d;
int v;
int r;
long long dfs(int i) {
  vis[i] = true;
  long long t = 1;
  for (auto x : adj[i]) {
    if (c[x] < c[r] || c[x] - c[r] > d) continue;
    if (c[x] == c[r] && x < r) continue;
    if (!vis[x]) t = (t % MOD * (dfs(x) + 1) % MOD) % MOD;
  }
  return t;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> d >> v;
  for (int i = 1; i < v + 1; i++) cin >> c[i];
  for (int i = 0; i < v - 1; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  long long ans = 0;
  for (int i = 1; i < v + 1; i++) {
    for (int i = 1; i < v + 1; i++) vis[i] = false;
    r = i;
    ans = (ans + dfs(i)) % MOD;
  }
  cout << ans << endl;
  return 0;
}
