import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Queue; public class Main_yukicoder329 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int n = sc.nextInt(); int m = sc.nextInt(); int[] w = new int[n]; for (int i = 0; i < n; i++) { w[i] = sc.nextInt(); } List> edges = new ArrayList>(); for (int i = 0; i < n; i++) { edges.add(new ArrayDeque()); } for (int i = 0; i < m; i++) { int ii = sc.nextInt() - 1; int jj = sc.nextInt() - 1; if (ii != jj) { edges.get(jj).add(ii); } } long ret = 0; for (int s = 0; s < n; s++) { Queue q = new ArrayDeque(); boolean[] used = new boolean[n]; q.add(s); used[s] = true; while (!q.isEmpty()) { int u = q.remove(); ret = (ret + getF(w[u], w[s])) % MOD; for (int e : edges.get(u)) { if (!used[e] && w[e] >= w[s]) { q.add(e); used[e] = true; } } } } pr.println(ret); pr.close(); sc.close(); } private static final long MOD = 1_000_000_007; private static long[][] dp; private static long getF(int s, int u) { if (dp == null) { dp = new long[1000 + 1][1000 + 1]; dp[0][0] = 1; for (int i = 1; i <= 1000; i++) { for (int j = 1; j <= i; j++) { dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD; dp[i][j] = dp[i][j] * j % MOD; } } } return dp[s][u]; } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }