#include <bits/stdc++.h>
using namespace std;
int d, minNode, V[2003];
vector<int> A[2003];
int DFS(int u, int parent) {
  if (V[u] < V[minNode] || (V[u] == V[minNode] && u < minNode) ||
      V[u] - V[minNode] > d)
    return 1;
  long long c = 1;
  for (vector<int>::iterator p = A[u].begin(); p != A[u].end(); ++p)
    if (*p != parent) c = (c * DFS(*p, u)) % 1000000007;
  return (c + 1) % 1000000007;
}
int solve(int n) {
  int c = 0, i;
  for (i = 1; i <= n; ++i) {
    minNode = i;
    c = (c + (DFS(i, -1) + 1000000007 - 1) % 1000000007) % 1000000007;
  }
  return c;
}
int main() {
  int n, u, v, i;
  scanf("%d %d", &d, &n);
  for (i = 1; i <= n; ++i) scanf("%d", V + i);
  for (i = 1; i < n; ++i) {
    scanf("%d %d", &u, &v);
    A[u].push_back(v), A[v].push_back(u);
  }
  printf("%d\n", solve(n));
  return 0;
}
