#include <bits/stdc++.h>
using namespace std;
long long dx[] = {1, 0, -1, 0};
long long dy[] = {0, 1, 0, -1};
long long gcd(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
long long expo(long long n, long long m) {
  long long r = 1;
  while (m > 0) {
    if (m % 2) r = (r * n) % 1000000007;
    n = (n * n) % 1000000007;
    m = m / 2;
  }
  return r % 1000000007;
}
vector<long long> adj[100000];
bool vis[100000];
vector<long long> f(100000);
vector<long long> c(100000);
long long d;
void dfs(long long s, long long root) {
  f[s] = 1;
  vis[s] = true;
  for (long long i = 0; i < adj[s].size(); i++) {
    long long p = adj[s][i];
    if (vis[p]) continue;
    if (c[p] < c[root] || c[p] > c[root] + d) continue;
    if (c[p] == c[root] && p > root) continue;
    dfs(p, root);
    f[s] = (f[s] * (f[p] + 1)) % 1000000007;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> d >> n;
  for (int i = 0; i < n; i++) cin >> c[i];
  for (int i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    adj[a - 1].push_back(b - 1);
    adj[b - 1].push_back(a - 1);
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) f[j] = 0, vis[j] = false;
    dfs(i, i);
    ans = (ans + f[i]) % 1000000007;
  }
  cout << ans;
  return 0;
}
