#include <bits/stdc++.h>
using namespace std;
int m = 1000000007;
int d, n;
int a[2007];
int wynik = 0;
int am = 0;
pair<int, int> tab[2007];
vector<int> G[2007];
int wyn[2007];
int odw[2007];
void DFS(int v) {
  odw[v] = 1;
  long long w = 1;
  for (int i = 0; i < G[v].size(); ++i) {
    if (!odw[G[v][i]]) {
      DFS(G[v][i]);
      w *= wyn[G[v][i]] + 1;
      w %= m;
    }
  }
  wyn[v] = w;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> d >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    am = max(am, a[i]);
  }
  for (int i = 1; i < n; ++i) cin >> tab[i].first >> tab[i].second;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      G[j].clear();
      wyn[j] = 0;
      odw[j] = 0;
    }
    for (int j = 0; j < n; ++j) {
      int wf = 0;
      int ws = 0;
      if (a[tab[j].first] > a[i] && a[tab[j].first] <= a[i] + d)
        wf = 1;
      else if (a[tab[j].first] == a[i] && tab[j].first >= i)
        wf = 1;
      if (a[tab[j].second] > a[i] && a[tab[j].second] <= a[i] + d)
        ws = 1;
      else if (a[tab[j].second] == a[i] && tab[j].second >= i)
        ws = 1;
      if (wf && ws) {
        G[tab[j].first].push_back(tab[j].second);
        G[tab[j].second].push_back(tab[j].first);
      }
    }
    DFS(i);
    wynik += wyn[i];
    wynik %= m;
  }
  cout << wynik << endl;
  return 0;
}
