#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int N, D, W[2010];
vector<int> G[2010];
long long dfs(int u, int f, int rt) {
  int n = G[u].size();
  long long ret = 1;
  for (int i = 0; i < n; i++) {
    int v = G[u][i];
    if (v == f || W[rt] < W[v] || (W[rt] == W[v] && v > rt) || W[rt] - W[v] > D)
      continue;
    ret = ret * (dfs(v, u, rt) + 1) % mod;
  }
  return ret;
}
int main() {
  scanf("%d%d", &D, &N);
  for (int i = 1; i <= N; i++) scanf("%d", &W[i]);
  int u, v;
  for (int i = 1; i < N; i++) {
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  long long ans = 0;
  for (int i = 1; i <= N; i++) ans = (ans + dfs(i, -1, i)) % mod;
  printf("%lld\n", ans);
  return 0;
}
