#include <bits/stdc++.h>
using namespace std;
long long n, d, a[2010], f[2010], Answer = 0;
vector<int> v[2010];
const long long Mod = 1e9 + 7;
long long DFS(int x, int p, int Node) {
  if (v[x].size() == 1 && v[x][0] == p) return 1;
  long long Res = 1;
  for (int i = 0; i < v[x].size(); i++) {
    int nxt = v[x][i];
    if (nxt != p) {
      if (a[nxt] < a[Node] || a[nxt] - a[Node] > d ||
          (a[nxt] == a[Node] && nxt < Node))
        continue;
      Res = ((Res % Mod) * (DFS(nxt, x, Node) + 1)) % Mod;
    }
  }
  return Res;
}
int main() {
  scanf("%d%d", &d, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n - 1; 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++) {
    Answer += DFS(i, -1, i);
    Answer %= Mod;
  }
  printf("%I64d", Answer);
  return 0;
}
