#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
bool closed[2005];
bool visited[2005];
int val[2005];
vector<vector<int> > edges(2005);
long long dfs(int cur, int v) {
  visited[cur] = true;
  long long res = 1;
  for (int i = 0; i < edges[cur].size(); i++) {
    if (closed[edges[cur][i]] || visited[edges[cur][i]] ||
        val[edges[cur][i]] > v) {
      continue;
    }
    res *= (dfs(edges[cur][i], v) + 1);
    res %= mod;
  }
  return res;
}
int main(int argc, const char* argv[]) {
  int n, d;
  cin >> d >> n;
  vector<pair<int, int> > order;
  for (int i = 1; i <= n; i++) {
    cin >> val[i];
    order.push_back(pair<int, int>(val[i], i));
  }
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  sort(order.begin(), order.end());
  long long answer = 0;
  for (int i = 0; i < n; i++) {
    pair<int, int> p = order[i];
    answer += dfs(p.second, p.first + d);
    answer %= mod;
    memset(visited, 0, sizeof(visited));
    closed[p.second] = true;
  }
  cout << answer << endl;
  return 0;
}
