#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000007;
int n, d, a[3000], used[3000], k;
long long f[3000];
vector<int> g[3000];
void init() {
  for (int i = 0; i < n; i++) {
    f[i] = 1;
    used[i] = 0;
  }
}
void dfs(int v) {
  used[v] = 1;
  for (int i = 0; i < g[v].size(); i++)
    if (used[g[v][i]] == 0 && a[k] <= a[g[v][i]] && a[g[v][i]] <= a[k] + d) {
      if (a[k] == a[g[v][i]] && k < g[v][i]) continue;
      dfs(g[v][i]);
      f[v] *= (f[g[v][i]] + 1);
      f[v] %= INF;
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> d >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    int x, y;
    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++) {
    init();
    k = i;
    dfs(i);
    ans += f[i];
    ans %= INF;
  }
  cout << ans << endl;
  return 0;
}
