#include <bits/stdc++.h>
using namespace std;
vector<int> a[2010];
long long ans, f[2010], oo;
int i, j, n, m, k, s, t, d;
int num[2010];
void dfs(int u, int fa, int p) {
  f[u] = 1;
  for (int i = 0; i < a[u].size(); ++i) {
    int v = a[u][i];
    if (v == fa) continue;
    if (num[v] >= num[p] && num[v] <= num[p] + d) {
      if (num[v] == num[p] && v < p) continue;
      dfs(v, u, p);
      f[u] = f[u] * (f[v] + 1) % oo;
    }
  }
}
int main() {
  scanf("%d%d", &d, &n);
  oo = 1000000007;
  for (i = 1; i <= n; ++i) scanf("%d", &num[i]);
  for (i = 1; i < n; ++i) {
    scanf("%d%d", &s, &t);
    a[s].push_back(t);
    a[t].push_back(s);
  }
  ans = 0;
  for (i = 1; i <= n; ++i) {
    memset(f, 0, sizeof(f));
    dfs(i, -1, i);
    ans = (ans + f[i]) % oo;
  }
  printf("%I64d\n", ans);
}
