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.
/*
 *
 * @author Mukesh Singh
 *
 */

import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
@SuppressWarnings("unchecked")
public class AB {	
	//solve test cases
	final static int MOD = 1000000007;
	int[][] gr ;
	int[] a ;
	long[] f ;
	int d ;
	boolean[] visited ;
	void solve() throws Exception {
		d = in.nextInt();
		int n = in.nextInt();
		int[] from = new int[n-1];
		gr = new int[n][];
		int[] to = new int[n-1];
		int[] p = new int[n];
		f = new long[n] ;
		visited = new boolean[n];
		a = new int[n];
		for(int i =0  ; i < n; ++i)
			a[i] = in.nextInt();
		for(int i = 0 ; i < n-1 ; ++i){
			int u = in.nextInt()-1;
			int v = in.nextInt()-1;
			++p[u];
			++p[v];
			from[i] = u ;
			to[i] = v ;
		}
		for(int i = 0 ; i < n; i++ )
			gr[i] = new int[p[i]];
		for(int i = 0 ; i < n-1; i++){
			gr[from[i]][--p[from[i]]]= to[i] ;
			gr[to[i]][--p[to[i]]]= from[i] ;
		}
		long ans = 0 ;
		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < n ; ++j){
				visited[j] = false ;
				f[j] = 0 ;
			}
			dfs(i,i);
			ans = (ans+f[i])%MOD;
		}
		System.out.println(ans);
	}
	void dfs(int u , int parent)
	{
		visited[u] = true ;
		f[u] = 1 ;
		for(int v: gr[u]){
			if(!visited[v]){
				if( a[v] < a[parent]||a[parent]+d < a[v]) continue ;
				if(a[v]==a[parent]&& v < parent) continue ;
				dfs(v,parent);
				f[u] = (f[u]*(f[v]+1))%MOD ;
			}
		}
	}
	
	//@ main function
	public static void main(String[] args) throws Exception {
		new AB();
	}
	
	InputReader in;
	PrintStream out ;
	DecimalFormat df ;
	AB() {
		try {
			File defaultInput = new File("file.in");
			if (defaultInput.exists()) 
				in = new InputReader("file.in");
			else 
				in = new InputReader();
			defaultInput = new File("file.out");
			if (defaultInput.exists()) 
				out = new PrintStream(new FileOutputStream("file.out"));
			else
				out = new PrintStream(System.out);
			df = new DecimalFormat("######0.00");
			solve();
			out.close();
		} 
		catch (Exception e) {
			e.printStackTrace();
			System.exit(261);
		}
	}
	
	class InputReader {
		BufferedReader reader;
		StringTokenizer tokenizer;
		
		InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in));
		}
		
		InputReader(String fileName) throws FileNotFoundException {
			reader = new BufferedReader(new FileReader(new File(fileName)));
		}
		
		String readLine() throws IOException {
			return reader.readLine();
		}
		
		String nextToken() throws IOException {
			while (tokenizer == null || !tokenizer.hasMoreTokens())
				tokenizer = new StringTokenizer(readLine());
			return tokenizer.nextToken();
		}
		
		boolean hasMoreTokens() throws IOException {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				String s = readLine();
				if (s == null)
					return false;
				tokenizer = new StringTokenizer(s);
			}
			return true;
		}
		
		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(nextToken());
		}
		
		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(nextToken());
		}
		
		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(nextToken());
		}
	}
}

