#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007, N = 2000;
int d, n;
vector<int> g[N];
int a[N], used[N], a_min, order[N];
void scan() {
  scanf("%d%d", &d, &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[--u].push_back(--v);
    g[v].push_back(u);
  }
}
inline int add(int x, int y) { return (x + 0ll + y) % MOD; }
inline int mul(int x, int y) { return (x * 1ll * y) % MOD; }
int dfs(int u, int p = -1) {
  if (used[u] || a[u] - a_min > d) {
    return 0;
  }
  int res = 1;
  for (int v : g[u]) {
    if (v == p) {
      continue;
    }
    res = mul(res, add(1, dfs(v, u)));
  }
  return res;
}
void solve() {
  for (int i = 0; i < n; ++i) {
    order[i] = i;
  }
  sort(order, order + n, [](int x, int y) -> bool { return a[x] < a[y]; });
  int res = 0;
  for (int i = 0; i < n; ++i) {
    int j = order[i];
    a_min = a[j];
    res = add(res, dfs(j));
    used[j] = 1;
  }
  printf("%d\n", res);
}
int main() {
  {
    ios::sync_with_stdio(false), cin.tie(nullptr),
        cout << fixed << setprecision(10);
  }
  scan();
  solve();
  return 0;
}
