#include <bits/stdc++.h>
using namespace std;
int n, u, v, k, a[2010], t, A, I;
long long int dp[2010], res, mod = 1000000007;
vector<int> to[2010];
bool vis[2010];
long long int DFS(int node) {
  if (dp[node] != -1) return dp[node];
  long long int ret = 1;
  for (int i = 0; i < to[node].size(); i++) {
    int T = to[node][i];
    if (vis[T] == 0 && a[T] <= A + k && a[T] >= A &&
        ((a[T] != a[I]) || (a[T] == a[I] && I < T))) {
      vis[T] = 1;
      ret *= (DFS(T) + 1), ret %= mod;
      vis[T] = 0;
    }
  }
  return (dp[node] = ret);
}
int main() {
  scanf("%d %d", &k, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d %d", &u, &v);
    to[u].push_back(v), to[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    memset(dp, -1, sizeof dp);
    A = a[i], I = i, vis[i] = 1;
    res += DFS(i), res %= mod;
    vis[i] = 0;
  }
  printf("%I64d", res);
  return 0;
}
