#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int N, D;
bool u;
vector<int> g[2000];
int a[2000];
int v[2000];
int vis[2000];
int ans;
inline void add(int &a, int b) {
  if (!u) b = MOD - b;
  a += b;
  if (a >= MOD) a -= MOD;
}
inline void mul(int &a, int b) { a = (a * 1ll * b) % MOD; }
int dfs(int s, int l, int r) {
  vis[s] = 1;
  int ret = 1;
  int ret1 = 0;
  for (vector<int>::iterator i = g[s].begin(); i != g[s].end(); i++)
    if (!vis[*i] && l <= a[*i] && a[*i] <= r) mul(ret, 1 + dfs(*i, l, r));
  add(ans, ret);
  return ret;
}
int main() {
  cin >> D >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    v[i] = a[i];
  }
  sort(v, v + N);
  for (int i = 1, a, b; i < N; i++) {
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int l = 0, r = 0, p = -1; l < N; l++) {
    for (; r < N && v[r] - v[l] <= D; r++)
      ;
    r--;
    memset(vis, 0, sizeof(vis));
    u = true;
    for (int i = 0; i < N; i++)
      if (v[l] <= a[i] && a[i] <= v[r] && !vis[i]) dfs(i, v[l], v[r]);
    memset(vis, 0, sizeof(vis));
    u = false;
    for (int i = 0; i < N; i++)
      if (v[l] <= a[i] && a[i] <= v[p] && !vis[i]) dfs(i, v[l], v[p]);
    p = r;
  }
  cout << ans << endl;
  return 0;
}
