#include <bits/stdc++.h>
using namespace std;
int blocked[2010] = {0};
vector<vector<int> > graph;
int visited[2010] = {0};
int valAt[2010] = {0};
long long f[2010] = {0};
vector<pair<int, int> > val;
int ele;
int d;
void dfs(int u, int root) {
  visited[u] = 1;
  f[u] = 1;
  for (int i = 0; i < (int)graph[u].size(); i++) {
    int v = graph[u][i];
    if (visited[v] or v == u or v == root or blocked[v]) continue;
    if (valAt[v] < valAt[ele] or valAt[v] > valAt[ele] + d) continue;
    dfs(v, u);
    f[u] = (f[u] * (f[v] + 1)) % 1000000007;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> d >> n;
  graph.resize(n);
  val.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> val[i].first;
    val[i].second = i;
    valAt[i] = val[i].first;
  }
  sort(val.begin(), val.end());
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a -= 1;
    b -= 1;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int vertex = val[i].second;
    ele = vertex;
    for (int j = 0; j < n; j++) visited[j] = f[j] = 0;
    dfs(vertex, vertex);
    ans = (ans + f[ele]) % 1000000007;
    blocked[vertex] = 1;
  }
  cout << ans << endl;
  return 0;
}
