#include <bits/stdc++.h>
using namespace std;
int d, n;
int u, v;
int val[2014];
vector<int> tree[2014];
int dfs(int root, int base, int curr) {
  int ans, to;
  if (base)
    if ((val[curr] - val[root] > d) || val[curr] < val[root] ||
        (val[curr] == val[root] && curr < root))
      return 0;
  ans = 1;
  for (int i = 0; i < tree[curr].size(); i++) {
    to = tree[curr][i];
    if (to == base) continue;
    ans = (long long int)ans * (1 + dfs(root, curr, to)) % 1000000007;
  }
  return ans;
}
int main(void) {
  scanf("%d%d", &d, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &val[i]);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    tree[u].push_back(v);
    tree[v].push_back(u);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans = (ans + dfs(i, 0, i)) % 1000000007;
  printf("%d\n", ans);
  return 0;
}
