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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class DValidSets {
        long mod = 1000000000 + 7;
        ArrayList<Integer>[] arrayList;
        int[] arr;
        int n;
        boolean[] visited;
        long[] f;
        int d;

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            d = in.scanInt();
            n = in.scanInt();
            arrayList = new ArrayList[n + 1];
            arr = new int[n + 1];
            for (int i = 0; i <= n; i++) {
                arrayList[i] = new ArrayList<>();
            }
            for (int i = 1; i <= n; i++) arr[i] = in.scanInt();
            for (int i = 0; i < n - 1; i++) {
                int x = in.scanInt();
                int y = in.scanInt();
                arrayList[x].add(y);
                arrayList[y].add(x);
            }

            long ans = 0;
            for (int i = 1; i <= n; i++) {
                visited = new boolean[n + 1];
                f = new long[n + 1];
                DFS(i, i);
                ans = (ans + f[i]) % mod;
            }

            out.println(ans);


        }

        void DFS(int u, int root) {
            visited[u] = true;
            f[u] = 1;
            for (int i = 0; i < arrayList[u].size(); i++) {
                int v = arrayList[u].get(i);
                if (!visited[v]) {
                    if ((arr[v] < arr[root]) || (arr[v] > arr[root] + d)) continue;
                    if ((arr[v] == arr[root]) && (v < root)) continue;
                    DFS(v, root);
                    f[u] = ((long) (f[u]) * (f[v] + 1)) % mod;
                }
            }
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}

