#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 2000 + 5;
struct Edge {
  int to, nxt;
} e[N << 1];
int n, m, hd[N], top, q[N], f[N], a[N], ans;
bool vis[N];
inline void addedge(int x, int y) {
  e[++top].to = y;
  e[top].nxt = hd[x];
  hd[x] = top;
  e[++top].to = x;
  e[top].nxt = hd[y];
  hd[y] = top;
}
inline int solve(int root) {
  int l, r, now, p, ch;
  memset(f, 0, sizeof f);
  for (vis[q[l = r = 1] = root] = 1; l <= r; ++l)
    for (p = hd[now = q[l]]; p; p = e[p].nxt)
      if (!vis[ch = e[p].to] &&
          (a[ch] < a[root] || (a[ch] == a[root] && ch > root)) &&
          a[root] - a[ch] <= m)
        vis[q[++r] = e[p].to] = 1;
  for (int i = r; i; --i) {
    p = hd[now = q[i]];
    f[now] = 1;
    vis[now] = 0;
    for (; p; p = e[p].nxt)
      if (!vis[ch = e[p].to] &&
          (a[ch] < a[root] || (a[ch] == a[root] && ch > root)) &&
          a[root] - a[ch] <= m)
        f[now] = f[now] * (long long)(f[ch] + 1) % MOD;
  }
  return f[root];
}
int main() {
  int x, y;
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &x, &y);
    addedge(x, y);
  }
  for (int i = 1; i <= n; ++i) ans = (ans + solve(i)) % MOD;
  printf("%d\n", ans);
  return 0;
}
