#include <bits/stdc++.h>
using namespace std;
int d, n;
vector<int> a;
int used[2001];
long long f[2001];
vector<vector<int> > g;
void dfs(int v, int start) {
  used[v] = 1;
  f[v] = 1;
  for (int i = 0; i < (int)g[v].size(); ++i) {
    int to = g[v][i];
    if (used[to]) continue;
    if (!(a[to] >= a[start] && a[to] <= a[start] + d)) continue;
    if (a[to] == a[start] && to < start) continue;
    dfs(to, start);
    f[v] *= (f[to] + 1);
    f[v] %= 1000000007;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> d >> n;
  a.resize(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  g.resize(n);
  int x, y;
  for (int i = 0; i < (n - 1); ++i) {
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  long long ans = 0;
  for (int i = 0; i < (n); ++i) {
    memset(used, 0, sizeof used);
    dfs(i, i);
    ans += f[i];
    ans %= 1000000007;
  }
  cout << ans;
  return 0;
}
