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.io.*;
import java.lang.*;
import java.util.*;
import java.math.*;
 
public class code
{
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            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; 
        } 
    } 
    
    static long P = 1000000007L;
    public static void main(String args[])throws IOException
    {
        FastReader scn = new FastReader();
        
        int d = scn.nextInt();
        int n = scn.nextInt();

        Node[] nodes = new Node[n];
        for(int i = 0; i < n; i++)
        {
            nodes[i] = new Node();
            nodes[i].weight = scn.nextInt();
        }

        for(int i = 0; i < n - 1; i++)
        {
            int a = scn.nextInt() - 1;
            int b = scn.nextInt() - 1;

            nodes[a].neighbors.add(nodes[b]);
            nodes[b].neighbors.add(nodes[a]);
        }

        Arrays.sort(nodes);
        for(int i = 0; i < n; i++)
        {
            nodes[i].sorted_index = i;
        }

        int i = 0;
        int j = 0;
        
        long count = 0;
        for(; i < n; i++)
        {
            while( j!= n - 1 && nodes[j + 1].weight - nodes[i].weight <= d)
                j++;

            long temp = dfs(nodes[i], i, j, nodes);
            count = (count + temp)%P;
        }

        System.out.println(count);
    }  

    public static long dfs(Node current, int l, int r, Node[] nodes)
    {
        current.visited = true;
        
        long ans = 1;
        for(Node next: current.neighbors)
        {
            if(!next.visited && next.sorted_index <= r && next.sorted_index >= l)
            {
                long p = dfs(next, l, r, nodes);
                ans = (ans * ( p + 1))%P;
            }
        }

        current.visited = false;
        return ans;
    }

    public static long getTwoPower(long power, long P)
    {
        if(power == 0)
            return 1;
        if(power == 1)
            return 2;
 
        long ans = getTwoPower(power/2, P);
        ans = (ans * ans)%P;
        if(power % 2 == 1)
            ans = (ans * 2)%P;
        return ans;
    }
  
    // public static int getLessThanIndex(ArrayList<Pair> list, int value, int l, int r)
    // {
    //     while( l <= r)
    //     {
    //         int middle = (l+r)/2;
 
    //         if(list.get(middle).b==value)
    //             return middle;
    //         else if(list.get(middle).b < value)
    //             l = middle + 1;
    //         else
    //             r = middle - 1;
    //     } 
    //     return r;
    // }
 
    // public static int getMoreThanIndex(ArrayList<Pair> list, int value, int l, int r)
    // {
    //     while( l <= r)
    //     {
    //         int middle = (l+r)/2;
 
    //         if(list.get(middle).b == value)
    //             return middle;
    //         else if(list.get(middle).b < value)
    //             l = middle + 1;
    //         else
    //             r = middle - 1;
    //     } 
    //     return l;
    // }
 
    public static long inverseModulo(long a, long P)
    {
        return powerModulo(a, P-2, P);
    }
 
    public static long powerModulo(long a, long p, long m)
    {   
        if(p==0)
            return 1;
 
        long temp = powerModulo(a, p/2, m);
        temp = (temp * temp)%m;
        if(p%2 == 0)
            return temp;
        else
            return (a * temp)%m;
 
    }
}
 
class Node implements Comparable<Node>
{
    int weight;
    int sorted_index;
    ArrayList<Node> neighbors;
    boolean visited;
    public Node()
    {
        neighbors = new ArrayList<>();
    }

    public int compareTo(Node n)
    {
        return this.weight - n.weight;
    }
 
}
 
class MutableInt
{
    int count;
    ArrayList<Integer> list;
    public MutableInt()
    {
        list = new ArrayList<>();
    }
}

class TrieNode
{
    HashMap<Character, TrieNode> map;
    boolean visited;
    int cost;

    public TrieNode()
    {
        map = new HashMap<>();
    }

    public TrieNode add(char c, boolean isGood, MutableInt result, int k)
    {
        if(map.containsKey(c))
        {
            TrieNode n = map.get(c);
            return n;
        }
        else
        {
            TrieNode n = new TrieNode();
            if(!isGood)
                n.cost = this.cost + 1;
            else
                n.cost = this.cost;

            if(n.cost <= k)
                result.count = result.count + 1;

            map.put(c, n);
            return n;
        }
    }

}