#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, x, y, an;
int a[2010], f[2010][2010][2];
vector<int> b[2010];
inline void add(int x, int y) {
  b[x].push_back(y);
  b[y].push_back(x);
}
inline void M(int &x, int y) {
  x += y;
  if (x >= 1000000007) x -= 1000000007;
}
void dfs(int x, int y) {
  int i, j, k, u;
  for (j = a[x]; j <= min(a[x] + m, 2000); j++) f[x][j][j == a[x]] = 1;
  for (i = 0; i < b[x].size(); i++) {
    int A = b[x][i];
    if (A == y) continue;
    dfs(A, x);
    for (j = 1; j <= 2000; j++) {
      int c[2] = {f[x][j][0], f[x][j][1]};
      for (k = 0; k <= 1; k++)
        for (u = 0; u <= 1; u++)
          M(f[x][j][k | u], 1ll * c[k] * f[A][j][u] % 1000000007);
    }
  }
  for (j = 1; j <= 2000; j++) M(an, f[x][j][1]);
}
int main() {
  scanf("%d%d", &m, &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n - 1; i++) {
    scanf("%d%d", &x, &y);
    add(x, y);
  }
  dfs(1, 0);
  printf("%d\n", an);
  return 0;
}
