#include <bits/stdc++.h>
using namespace std;
int n, d, aux[2005], cap[2005], v[2 * 2005], a[2005], viz[2005];
long long nrpos[2005], rez;
struct muchii {
  int x, y;
} muc[2005];
void citire() {
  int i, x, y;
  cin >> d >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i < n; i++) {
    cin >> x >> y;
    muc[i].x = x;
    muc[i].y = y;
    aux[x]++;
    aux[y]++;
  }
  cap[1] = 1;
  for (i = 2; i <= n + 1; i++) {
    cap[i] = cap[i - 1] + aux[i - 1];
    aux[i - 1] = cap[i - 1];
  }
  for (i = 1; i < n; i++) {
    x = muc[i].x;
    y = muc[i].y;
    v[aux[x]] = y;
    aux[x]++;
    v[aux[y]] = x;
    aux[y]++;
  }
}
void dfs(int nod, int rad) {
  int i;
  viz[nod] = 1;
  if ((a[rad] <= a[nod]) && (a[nod] <= a[rad] + d))
    nrpos[nod] = 1;
  else
    nrpos[nod] = 0;
  for (i = cap[nod]; i < cap[nod + 1]; i++)
    if (!viz[v[i]]) {
      dfs(v[i], rad);
      if ((a[rad] == a[v[i]]) && (rad > v[i]))
        ;
      else if ((a[rad] <= a[v[i]]) && (a[v[i]] <= a[rad] + d))
        nrpos[nod] *= (nrpos[v[i]] + 1);
      nrpos[nod] %= 1000000007;
    }
}
int main() {
  citire();
  for (int i = 1; i <= n; i++) {
    dfs(i, i);
    memset(viz, 0, sizeof(viz));
    rez += nrpos[i];
    rez %= 1000000007;
  }
  cout << rez;
  return 0;
}
