#include <bits/stdc++.h>
using namespace std;
inline long long qr() {
  long long x = 0, f = 1;
  char ch;
  while (!isdigit(ch = getchar()))
    if (ch == '-') f = -1;
  for (; isdigit(ch); x = x * 10 + ch - 48, ch = getchar())
    ;
  return x * f;
}
const int mod = 1e9 + 7;
long long ans, f[2019];
int n, D, a[2019];
vector<int> g[2019];
void dfs(int u, int ff, int id) {
  f[u] = 1;
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i];
    if (v == ff || a[v] > a[id] || (a[v] == a[id] && id < v) ||
        a[id] - a[v] > D)
      continue;
    dfs(v, u, id);
    f[u] = f[u] * (f[v] + 1) % mod;
  }
}
int main() {
  D = qr(), n = qr();
  for (int i = 1; i <= n; ++i) a[i] = qr();
  for (int i = 2; i <= n; ++i) {
    int x = qr(), y = qr();
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 1; i <= n; ++i) {
    memset(f, 0, sizeof f);
    dfs(i, 0, i);
    ans = (ans + f[i]) % mod;
  }
  printf("%lld\n", ans);
  return 0;
}
