#include <bits/stdc++.h>
using namespace std;
pair<int, int> DFSv(int v, vector<vector<int> > &G, vector<int> &A,
                    vector<bool> &vis) {
  vis[v] = 1;
  pair<int, int> ans = make_pair(0, 1);
  for (int i = (0); i <= ((int)(G[v]).size() - 1); ++i)
    if (!vis[G[v][i]]) {
      pair<int, int> tmp = DFSv(G[v][i], G, A, vis);
      ans.second = ((long long int)ans.second * (tmp.second + 1)) % 1000000007;
      ans.first = ((long long int)ans.first + tmp.first) % 1000000007;
    }
  ans.first = ((long long int)ans.first + ans.second) % 1000000007;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  int d, n;
  cin >> d >> n;
  vector<int> A(n);
  for (int i = (0); i <= ((int)(A).size() - 1); ++i) cin >> A[i];
  vector<int> Val = A;
  sort(Val.begin(), Val.end());
  Val.resize(unique(Val.begin(), Val.end()) - Val.begin());
  vector<vector<int> > G(n);
  for (int i = (1); i <= (n - 1); ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  int ans = 0;
  for (int j = (0); j <= ((int)(Val).size() - 1); ++j) {
    int v = Val[j];
    vector<bool> vis(n);
    for (int i = (0); i <= (n - 1); ++i) vis[i] = (A[i] > v || A[i] < v - d);
    for (int i = (0); i <= ((int)(vis).size() - 1); ++i)
      if (!vis[i]) {
        pair<int, int> tmp = DFSv(i, G, A, vis);
        ans = ((long long int)ans + tmp.first) % 1000000007;
      }
    for (int i = (0); i <= (n - 1); ++i) vis[i] = (A[i] >= v || A[i] < v - d);
    for (int i = (0); i <= ((int)(vis).size() - 1); ++i)
      if (!vis[i]) {
        pair<int, int> tmp = DFSv(i, G, A, vis);
        ans = ((long long int)ans - tmp.first + 1000000007) % 1000000007;
      }
  }
  cout << ans;
  return 0;
}
