#include <bits/stdc++.h>
using namespace std;
long long int dfs(int s, int e, vector<int> &A, vector<bool> &vis,
                  vector<vector<int> > &adj, int d, int mi) {
  vis[s] = true;
  long long int val = 1;
  for (int i = 0; i < adj[s].size(); i++) {
    if (vis[adj[s][i]] == true) continue;
    if (A[adj[s][i]] == mi && adj[s][i] < e) {
      continue;
    }
    if (A[adj[s][i]] >= mi && A[adj[s][i]] <= d + mi) {
      val = (((1 + dfs(adj[s][i], e, A, vis, adj, d, mi)) % 1000000007) * val) %
            1000000007;
    }
  }
  return val % 1000000007;
}
int main() {
  int d, n;
  cin >> d >> n;
  vector<vector<int> > adj(n);
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  long long int total = 0;
  for (int i = 0; i < n; i++) {
    vector<bool> vis(n, false);
    total = (total + dfs(i, i, A, vis, adj, d, A[i])) % 1000000007;
  }
  cout << total;
  return 0;
}
