#include <bits/stdc++.h>
using namespace std;
int n, d, head[2100], cnt, a[2100];
long long ans, dp[2100];
struct Node {
  int to, next;
} edge[2100 << 1];
void addEdge(int from, int to) {
  edge[cnt] = (Node){to, head[from]};
  head[from] = cnt++;
}
void dfs(int u, int fa, int rt) {
  dp[u] = 1;
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (v == fa) continue;
    if ((a[v] < a[rt] && a[rt] - a[v] <= d) || (a[v] == a[rt] && rt < v)) {
      dfs(v, u, rt);
      dp[u] = (dp[u] + dp[u] * dp[v]) % 1000000007;
    }
  }
}
int main() {
  int u, v;
  memset(head, -1, sizeof(head));
  scanf("%d%d", &d, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    addEdge(u, v);
    addEdge(v, u);
  }
  for (int i = 1; i <= n; i++) {
    dfs(i, -1, i);
    ans = (ans + dp[i]) % 1000000007;
  }
  printf("%lld", ans);
  return 0;
}
