#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int d, n;
int a[N];
int ans = 0;
int cnt[N];
vector<int> g[N];
void dfs(int v, int id, int p = -1) {
  cnt[v] = 1;
  for (int j = 0; j < g[v].size(); ++j) {
    int to = g[v][j];
    if (a[to] > a[id] || to == p) continue;
    if ((a[to] == a[id] && to < id) || (a[to] < a[id] && a[id] - a[to] <= d)) {
      dfs(to, id, v);
      cnt[v] = (cnt[v] * 1ll * (cnt[to] + 1)) % 1000000007;
    }
  }
}
int main() {
  scanf("%d%d", &d, &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 1; i <= n; ++i) {
    memset(cnt, 0, sizeof cnt);
    dfs(i, i);
    ans = (ans + cnt[i]) % 1000000007;
  }
  printf("%d\n", ans);
  return 0;
}
