#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
const int MAXE = 4005;
const int mod = 1e9 + 7;
struct Edge {
  int v, n;
  Edge() {}
  Edge(int v, int n) : v(v), n(n) {}
};
Edge E[MAXE];
int H[MAXN], cntE;
int val[MAXN];
int vis[MAXN][MAXN];
long long dp[MAXN];
int d, n;
int root;
void clear() {
  cntE = 0;
  memset(H, -1, sizeof H);
  memset(vis, 0, sizeof vis);
}
void addedge(int u, int v) {
  E[cntE] = Edge(v, H[u]);
  H[u] = cntE++;
}
long long dfs(int u, int fa) {
  dp[u] = 1;
  long long ans = 1;
  for (int i = H[u]; ~i; i = E[i].n) {
    int v = E[i].v;
    if (v == fa) continue;
    if (val[v] > val[root] || vis[root][v] || val[root] - val[v] > d) continue;
    if (val[root] == val[v]) vis[root][v] = vis[v][root] = 1;
    long long tmp = dfs(v, u);
    ans = (ans + tmp * dp[u] % mod) % mod;
    dp[u] = (dp[u] + tmp * dp[u]) % mod;
  }
  return ans;
}
void solve() {
  int u, v;
  clear();
  for (int i = (1); i <= (n); ++i) scanf("%d", &val[i]);
  for (int i = (1); i < (n); ++i) {
    scanf("%d%d", &u, &v);
    addedge(u, v);
    addedge(v, u);
  }
  long long ans = 0;
  for (int i = (1); i <= (n); ++i) {
    root = i;
    ans = (ans + dfs(i, 0)) % mod;
  }
  printf("%I64d\n", ans);
}
int main() {
  while (~scanf("%d%d", &d, &n)) solve();
  return 0;
}
