As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it.

We call a set S of tree nodes valid if following conditions are satisfied:

  1. S is non-empty.
  2. S is connected. In other words, if nodes u and v are in S, then all nodes lying on the simple path between u and v should also be presented in S.
  3. <image>.



Your task is to count the number of valid sets. Since the result can be very large, you must print its remainder modulo 1000000007 (109 + 7).

Input

The first line contains two space-separated integers d (0 ≤ d ≤ 2000) and n (1 ≤ n ≤ 2000).

The second line contains n space-separated positive integers a1, a2, ..., an(1 ≤ ai ≤ 2000).

Then the next n - 1 line each contain pair of integers u and v (1 ≤ u, v ≤ n) denoting that there is an edge between u and v. It is guaranteed that these edges form a tree.

Output

Print the number of valid sets modulo 1000000007.

Examples

Input

1 4
2 1 3 2
1 2
1 3
3 4


Output

8


Input

0 3
1 2 3
1 2
2 3


Output

3


Input

4 8
7 8 7 5 4 6 4 10
1 6
1 2
5 8
1 3
3 5
6 7
3 4


Output

41

Note

In the first sample, there are exactly 8 valid sets: {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {3, 4} and {1, 3, 4}. Set {1, 2, 3, 4} is not valid, because the third condition isn't satisfied. Set {1, 4} satisfies the third condition, but conflicts with the second condition.
import java.util.Scanner;
import java.util.List;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Anudeep Nekkanti
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {

  private final Mod MOD = new Mod(1000000007);
  List<Integer>[] adj = new List[2000];
  int[] a = new int[2000];
  boolean[] valid = new boolean[2000];
  int[][] dp = new int[2000][3];
  private int[] v = new int[2000];
  private int curMin;
  int d;
  int ans = 0;

  public void solve(int testNumber, Scanner in, PrintWriter out) {
    d = in.nextInt();
    int n = in.nextInt();

    for (int i = 0; i < n; i++) {
      a[i] = in.nextInt();
    }

    for (int i = 0; i < n; i++) {
      adj[i] = new ArrayList<>();
    }

    for (int i = 0; i < n - 1; i++) {
      int u = in.nextInt();
      int v = in.nextInt();
      u--;
      v--;
      adj[u].add(v);
      adj[v].add(u);
    }

    for (int min = 1; min < 2001; min++) {
      curMin = min;
      for (int i = 0; i < n; i++) {
        valid[i] = true;
        if ((a[i] < min) || ((a[i] - min) > d)) {
          valid[i] = false;
        }
        v[i] = 0;
      }

      for (int i = 0; i < n; i++) {
        if (valid[i] && v[i] == 0) {
          solve(i, -1);
        }
      }
    }
    out.println(ans);
  }

  private void solve(int cur, int prev) {
    dp[cur][0] = dp[cur][1] = dp[cur][2] = 0;
    v[cur] = 1;

    for (int i = 0; i < adj[cur].size(); i++) {
      int u = adj[cur].get(i);
      if (u != prev && valid[u]) {
        solve(u, cur);
      }
    }

    int[] product = new int[3];
    for (int i = 0; i < 3; i++) {
      product[i] = 1;
      for (int j = 0; j < adj[cur].size(); j++) {
        int u = adj[cur].get(j);
        if (u != prev && valid[u]) {
          product[i] = MOD.mul(product[i], dp[u][i] + 1);
        }
      }
    }

    // 0 is must select
    if (a[cur] == curMin) {
      dp[cur][0] = product[2];
    } else {
      dp[cur][0] = product[2];
      dp[cur][0] = MOD.sub(dp[cur][0], product[1]);
    }

    // 1 is dont select
    if (a[cur] == curMin) {
      dp[cur][1] = 0;
    } else {
      dp[cur][1] = product[1];
    }

    // 2 is anything
    dp[cur][2] = product[2];

    ans = MOD.add(ans, dp[cur][0]);
  }

}

class Mod {
  private int MOD;

  public Mod(int MOD) {
    this.MOD = MOD;
  }

  public int add(int a, int b) {
    a += b;
    if(a >= MOD) {
      a -= MOD;
    }
    return a;
  }

  public int sub(int a, int b) {
    a -= b;
    if( a < 0 ) {
      a += MOD;
    }
    return a;
  }

  public int mul(int a, int b) {
    long ret = a;
    ret *= b;
    ret %= MOD;
    if(ret < 0) {
      ret += MOD;
    }
    return (int) ret;
  }
}

