#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long pwr(long long base, long long p, long long mod) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p >>= 1;
  }
  return ans;
}
long long modInv(long long n, long long mod) { return pwr(n, mod - 2, mod); }
int bitCount(int n) {
  int c = 0;
  while (n) {
    c++;
    n &= n - 1;
  }
  return c;
}
int d;
vector<int> adj[2002];
int arr[2002];
long long solve(int v, int parent, int root) {
  if (arr[v] < arr[root]) return 1;
  if (arr[v] > arr[root] + d) return 1;
  if (arr[v] == arr[root] && v < root) return 1;
  int j;
  long long ans = 1;
  for (j = 0; j < adj[v].size(); j++) {
    int vv = adj[v][j];
    if (vv != parent) ans = (ans * solve(vv, v, root)) % (1000000007LL);
  }
  return (ans + 1) % (1000000007LL);
}
int main() {
  int n;
  cin >> d >> n;
  int i, e = n - 1;
  for (i = 1; i <= n; i++) cin >> arr[i];
  while (e--) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  long long ans = 0;
  for (i = 1; i <= n; i++) {
    long long z = solve(i, 0, i);
    ans = (ans + z) % (1000000007LL);
  }
  ans -= n;
  if (ans < 0) ans += (1000000007LL);
  cout << ans;
  return 0;
}
