#include <bits/stdc++.h>
using namespace std;
const double error = 1e-15;
const double pi = 2 * acos(0);
const int maxn = (int)1e5 + 10;
const int mod = (int)1e9 + 7;
int dx[] = {0, -1, 0, +1, -1, -1, +1, +1};
int dy[] = {-1, 0, +1, 0, -1, +1, +1, -1};
int A[2005], B[2005];
vector<int> G[2005];
int n, color[2005], cst, d;
long long DFS_Visit(int u, int j) {
  int i, v, l;
  long long cnt = 1;
  color[u] = j;
  l = G[u].size();
  for (i = 0; i < l; i++) {
    v = G[u][i];
    if (color[v] != j && A[v] <= cst && (cst - A[v]) <= d && B[v] == 1) {
      cnt = (cnt * (DFS_Visit(v, j) + 1)) % mod;
    }
  }
  return cnt;
}
vector<pair<int, int> > vv;
int main() {
  ios_base::sync_with_stdio(0);
  int n, i, x, y, nd;
  long long ans = 0;
  cin >> d >> n;
  for (i = 1; i <= n; i++) {
    cin >> A[i];
    vv.push_back(make_pair(A[i], i));
  }
  for (i = 1; i < n; i++) {
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  sort(vv.begin(), vv.end());
  for (i = 1; i <= n; i++) {
    nd = vv[i - 1].second;
    cst = A[nd];
    ans = (ans + DFS_Visit(nd, i)) % mod;
    B[nd] = 1;
  }
  cout << ans << endl;
  return 0;
}
