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.math.BigInteger;
import java.util.*;

import static java.lang.Math.min;
import static java.lang.Math.max;

public class Main {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {

        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    public static void main(String[] args) {
        new Main().run();
        // Sworn to fight and die
    }

    public static void mergeSort(int[] a) {
        mergeSort(a, 0, a.length - 1);
    }

    private static void mergeSort(int[] a, int levtIndex, int rightIndex) {
        final int MAGIC_VALUE = 2;
        if (levtIndex < rightIndex) {
            if (rightIndex - levtIndex <= MAGIC_VALUE) {
                insertionSort(a, levtIndex, rightIndex);
            } else {
                int middleIndex = (levtIndex + rightIndex) / 2;
                mergeSort(a, levtIndex, middleIndex);
                mergeSort(a, middleIndex + 1, rightIndex);
                merge(a, levtIndex, middleIndex, rightIndex);
            }
        }
    }

    private static void merge(int[] a, int levtIndex, int middleIndex,
                              int rightIndex) {
        int length1 = middleIndex - levtIndex + 1;
        int length2 = rightIndex - middleIndex;
        int[] levtArray = new int[length1];
        int[] rightArray = new int[length2];
        System.arraycopy(a, levtIndex, levtArray, 0, length1);
        System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
        for (int k = levtIndex, i = 0, j = 0; k <= rightIndex; k++) {
            if (i == length1) {
                a[k] = rightArray[j++];
            } else if (j == length2) {
                a[k] = levtArray[i++];
            } else {
                a[k] = levtArray[i] <= rightArray[j] ? levtArray[i++]
                        : rightArray[j++];
            }
        }
    }

    private static void insertionSort(int[] a, int levtIndex, int rightIndex) {
        for (int i = levtIndex + 1; i <= rightIndex; i++) {
            int current = a[i];
            int j = i - 1;
            while (j >= levtIndex && a[j] > current) {
                a[j + 1] = a[j];
                j--;
            }
            a[j + 1] = current;
        }
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    class LOL implements Comparable<LOL> {

        long x;
        int y;

        public LOL(long x, int y) {
            this.x = x;
            this.y = y;

        }

        @Override
        public boolean equals(Object object) {
            boolean sameSame = false;

            if (object != null && object instanceof LOL) {
                sameSame = ((this.x == ((LOL) object).x) && (this.y == ((LOL) object).y));
            }

            return sameSame;
        }

        @Override
        public int compareTo(LOL o) {
            if (x > o.x) return 1;
            if (x < o.x) return -1;
            return 0;
            // return o.x * o.y - x * y; // <----
        }

    }

    Map <Integer, ArrayList<Integer>> g = new HashMap<Integer, ArrayList<Integer>>();



    int mod = 1000 * 1000 * 1000 + 7;
    int n;
    int d;

    long [] f;
    int [] a;
    boolean [] isVisited;

    public void dfs(int v, int root) {
        f[v] = 1;
        isVisited[v] = true;
        for (int i = 0; i < g.get(v).size(); i++) {
            int u = g.get(v).get(i);
            if (!isVisited[u]) {


                if (a[u] < a[root] || a[u] > a[root] + d) {
                    continue;
                }

                if (a[u] == a[root] && u < root) {
                    continue;
                }

                dfs(u, root);
                f[v] %= mod;
                f[v] = (f[v] * ((f[u] + 1) % mod)) % mod;

            }
        }
    }






    public void solve() throws IOException {
        d = readInt();
        n = readInt();

        a = new int[n + 1];

        for (int i = 1; i <= n; i++) {
            a[i] = readInt();
        }



        for (int i = 1; i < n; i++) {
            int temp1 = readInt();
            int temp2 = readInt();

            if (!g.containsKey(temp1)) {
                g.put(temp1, new ArrayList<Integer>());
            }

            if (!g.containsKey(temp2)) {
                g.put(temp2, new ArrayList<Integer>());
            }

            g.get(temp1).add(temp2);
            g.get(temp2).add(temp1);

        }

        long result = 0;

        for (int i = 1; i <= n; i++) {
            isVisited = new boolean[n + 1];
            f = new long[n + 1];
            dfs(i, i);
            result = (result + f[i]) % mod;
        }

        out.println(result);















    }


}