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.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
    long MOD = 1000000007L;
    public class Obj implements Comparable<Obj>{
        public int a;
        public int b;
        
        public Obj(int a_, int b_){
            a = a_;
            b = b_;
        }
        
        public int compareTo(Obj other){
            if (a != other.a){
                return a - other.a;
            }else{
                return b - other.b;
            }
        }
        
    }
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
        Codechef cf = new Codechef();
        cf.Solve();
	}
	
	
	public void Solve(){
        MyScanner sc = new MyScanner();
        int d = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n];
        ArrayList<ArrayList<Integer>> con = new ArrayList<ArrayList<Integer>>();
        for (int i = 0; i < n; ++i){
            a[i] = sc.nextInt();
            con.add(new ArrayList<Integer>());
        }
        
        for (int i = 0; i < n - 1; ++i){
            int u = sc.nextInt();
            int v = sc.nextInt();
            u--;
            v--;
            con.get(u).add(v);
            con.get(v).add(u);
        }
        
        long res = 0L;
        for (int i = 0; i < n; ++i){
            boolean[] vis = new boolean[n];
            long[] f = new long[n];
            DFS(i, vis, con, a, d, i, f);
            // System.out.println(i + " " + f[i]);
            res = (res + f[i]) % MOD; 
        }
        System.out.println(res);
	}
	
	public void DFS(int cur, boolean[] vis,ArrayList<ArrayList<Integer>> con, int[] a, int d, int root, long[] f){
	    f[cur] = 1L;
	    vis[cur] = true;
	    ArrayList<Integer> co = con.get(cur);
	    for (int i = 0; i < co.size(); ++i){
	        int u = co.get(i);
	        if (vis[u]) continue;
	        int j = a[u];
	        if ((j < a[root]) || (j > d + a[root])) continue;
	        if ((j == a[root]) && (u < root)) continue;
	        DFS(u, vis, con, a, d, root, f);
	        f[cur] = (f[cur] * (f[u] + 1)) % MOD;
	    }
	}
	

	//-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;
      
   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
      try {
         str = br.readLine();
      } catch (IOException e) {
         e.printStackTrace();
      }
      return str;
      }

   }
}