from collections import defaultdict as ddict p = 10**9+7 N,M = map(int,raw_input().split()) w = map(int,raw_input().split()) w_max = max(w) E = [[0]*N for i in xrange(N)] for i in xrange(N): E[i][i] = w[i] for t in xrange(M): i,j = map(lambda x:int(x)-1,raw_input().split()) E[i][j] = w[i] for k in xrange(N): for i in xrange(N): for j in xrange(N): E[i][j] = max(E[i][j],min(E[i][k],E[k][j])) C = [[0] for i in xrange(w_max+1)] C[0].extend([1,0]) for i in xrange(1,w_max+1): C[i].extend([(C[i-1][j]+C[i-1][j+1])%p for j in xrange(i+1)]+[0]) F = [ddict(int) for i in xrange(w_max+1)] for i in xrange(N): wi = w[i] for j in xrange(N): wj = w[j] if wj <= E[i][j]: F[wi][wj]+=1 ans = 0 for wi in xrange(1,w_max+1): for wj,v in F[wi].iteritems(): ans += v*sum(C[wj][k+1]*pow(wj-k,wi,p)*((-1)**(k%2)) for k in xrange(wj)) % p ans %= p print ans