#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
pair<int, int> a[2002];
vector<int> gr[2002];
bool used[2002];
int sz[2002];
int n, d, st;
long long dfs(int v, int par) {
  long long ans = 1;
  for (int i = 0; i < gr[v].size(); i++)
    if (!used[gr[v][i]] && gr[v][i] != par && st - sz[gr[v][i]] <= d)
      (ans *= (dfs(gr[v][i], v) + 1)) %= mod;
  return ans;
}
int main() {
  cin >> d >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
    sz[i] = a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + n + 1);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    gr[x].push_back(y);
    gr[y].push_back(x);
  }
  memset(used, 0, 2001);
  long long answer = 0;
  for (int i = n; i; i--) {
    st = a[i].first;
    (answer += dfs(a[i].second, -1)) %= mod;
    used[a[i].second] = 1;
  }
  cout << answer << "\n";
  return 0;
}
