#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
const long long INF = 1e9 + 7;
long long d, n, in[2000], a, b;
vector<long long> adj[2000];
long long id;
long long dfs(long long e, long long p) {
  long long ret = 0;
  if (in[e] >= in[id] && in[e] <= in[id] + d && (in[e] > in[id] || e <= id)) {
    ret = 1;
    for (auto i : adj[e]) {
      if (i != p) {
        ret = (ret * (dfs(i, e) + 1)) % INF;
      }
    }
  }
  return ret;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> d >> n;
  for (long long i = 0; i < n; i++) cin >> in[i];
  for (long long i = 0; i < n - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  long long res = 0;
  for (long long i = 0; i < n; i++) {
    id = i;
    res = (res + dfs(i, i)) % INF;
  }
  cout << res << "\n";
}
