#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const int MOD = 1000000007;
int d, n;
int a[N];
int ord[N], rnk[N];
vector<int> v[N];
inline bool cmp(int x, int y) { return a[x] > a[y]; }
int ans = 0;
int sz[N];
inline void dfs(int x, int top) {
  sz[x] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    int next = v[x][i];
    if (sz[next] || rnk[next] < rnk[top] || a[top] - a[next] > d) continue;
    dfs(next, top);
    sz[x] = (long long)sz[x] * (sz[next] + 1) % MOD;
  }
}
int main() {
  scanf("%d%d", &d, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), ord[i] = i;
  sort(ord + 1, ord + n + 1, cmp);
  for (int i = 1; i <= n; i++) rnk[ord[i]] = i;
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    memset(sz, 0, sizeof(sz));
    dfs(ord[i], ord[i]);
    ans = (ans + sz[ord[i]]) % MOD;
  }
  printf("%d\n", ans);
  return 0;
}
