#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 10 ** 9 + 7 N, M = map(int, readline().split()) W = np.array(readline().split(), np.int64) IJ = np.array(read().split(), np.int32) - 1 I = IJ[::2] J = IJ[1::2] A = np.zeros((N, N), np.int32) np.fill_diagonal(A, W) A[I, J] = np.minimum(W[I], W[J]) for i in range(N): for j in range(N): A[i, j] = np.max(np.minimum(A[i, :], A[:, j])) # 全射の数え上げ U = 1000 dp = np.zeros((U + 1, U + 1), np.int64) dp[0, 0] = 1 for n in range(U): dp[n + 1] += np.arange(U + 1) * dp[n] dp[n + 1, 1:] += np.arange(1, U + 1) * dp[n, :-1] dp[n + 1] %= MOD reachable = A == W[None, :] answer = (dp[W][:, W] * reachable).sum() % MOD print(answer)