#include <bits/stdc++.h>
using namespace std;
vector<int> G[2001];
int V[2001];
int n, d, root;
int a, b;
long long ans;
long long dfs(int v, int parent) {
  long long sum = 1;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i];
    if (u == parent) continue;
    if (V[root] < V[u]) continue;
    if (V[root] == V[u] && root < u) continue;
    if (V[root] - V[u] <= d) sum = (sum * (dfs(u, v) + 1)) % 1000000007;
  }
  return sum;
}
int main() {
  cin >> d >> n;
  for (int i = 1; i <= n; i++) {
    cin >> V[i];
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    root = i;
    ans += dfs(i, -1);
    ans %= 1000000007;
  }
  cout << ans << endl;
  return 0;
}
