#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const long long N = 2010, mod = 1000000007;
struct edge {
  long long v, nxt;
} e[N << 1];
long long head[N], cnt, n, d, a[N], f[N], x, y, ans;
inline void add(long long u, long long v) {
  e[++cnt].v = v;
  e[cnt].nxt = head[u];
  head[u] = cnt;
}
inline void dfs(long long u, long long fa, long long g) {
  f[u] = 1;
  for (long long i = head[u]; i; i = e[i].nxt) {
    long long v = e[i].v;
    if (v == fa) continue;
    if (a[g] - a[v] > d) continue;
    if (a[g] > a[v] || (a[g] == a[v] && g >= v)) {
      dfs(v, u, g);
      f[u] += f[u] * f[v] % mod;
      f[u] %= mod;
    }
  }
}
signed main() {
  d = read();
  n = read();
  for (long long i = 1; i <= n; ++i) a[i] = read();
  for (long long i = 1; i < n; ++i) {
    x = read();
    y = read();
    add(x, y);
    add(y, x);
  }
  for (long long i = 1; i <= n; ++i) {
    dfs(i, 0, i);
    ans = (ans + f[i]) % mod;
  }
  printf("%lld", ans);
  return 0;
}
