#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int a[2010];
bool vis[2010];
long long sum;
vector<int> edge[2010];
long long DFS(int u, int d, int fa, int root) {
  long long ret = 1;
  for (int i = 0; i < edge[u].size(); i++) {
    int v = edge[u][i];
    if (v != fa && a[root] >= a[v] && a[root] - a[v] <= d &&
        !(a[root] == a[v] && v > root)) {
      ret = ret * (DFS(v, d, u, root) + 1) % mod;
    }
  }
  return ret;
}
int main() {
  int n, d;
  scanf("%d %d", &d, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    sum = (sum + DFS(i, d, -1, i)) % mod;
    vis[i] = true;
  }
  printf("%lld\n", sum);
  return 0;
}
