#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000000")
using namespace std;
long int long d, n;
vector<long int long> a;
vector<vector<long int long> > g;
vector<char> used;
long int long res = 0;
vector<long int long> ans;
const long int long MOD = 1e9 + 7;
vector<long int long> dist;
void dfs(long int long v, long int long root) {
  used[v] = 1;
  dist[v] = 1;
  for (auto to : g[v]) {
    if (!used[to]) {
      if ((a[to] < a[root]) || (a[to] > a[root] + d)) continue;
      if ((a[to] == a[root]) && (to < root)) continue;
      dfs(to, root);
      dist[v] = (dist[v] + dist[v] * dist[to]) % MOD;
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin >> d >> n;
  g.resize(n);
  a.resize(n);
  for (long int long i = 0; i < n; ++i) cin >> a[i];
  for (long int long i = 0; i < n - 1; ++i) {
    long int long v, u;
    cin >> v >> u;
    --v, --u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  for (long int long i = 0; i < n; ++i) {
    used.assign(n, 0);
    dist.assign(n, 0);
    dfs(i, i);
    res = (res + dist[i]) % MOD;
  }
  cout << res;
  return 0;
}
