#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 5;
const long long mod = 1e9 + 7;
const int alphabet = 26;
const int inf = INT_MAX;
const long long linf = 1e18 + 9;
inline long long cnm(char ch) { return (ch - '0'); }
inline long long cap(char ch) { return (ch - 'a'); }
inline void instr(string& s, long long& n) {
  cin >> s;
  n = s.length();
}
inline void instr(string& s) { cin >> s; }
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
vector<int> g[maxn];
bool vis[maxn];
long long f[maxn];
long long a[maxn], d;
long long dfs(long long node, long long par, long long root) {
  long long res = 1;
  for (int i = 0; i < g[node].size(); i++) {
    long long v = g[node][i];
    if (v == par) continue;
    if ((a[v] < a[root]) or (a[v] > a[root] + d)) continue;
    if ((a[v] == a[root]) and (v < root)) continue;
    res = res * (dfs(v, node, root) + 1) % mod;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, k, m, n;
  cin >> d >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 0; i < n - 1; i++) {
    long long x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  long long ans = 0;
  for (i = 1; i <= n; i++) {
    ans = (ans + dfs(i, -1, i)) % mod;
  }
  cout << ans;
  return 0;
}
