#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N,M; int W[300]; int I[40404],J[40404]; ll mo=1000000007; int mat[300][300]; static const int N_=1020; static ll C_[N_][N_]; ll fact[1010][1010]; ll dp[1010][1010]; void solve() { int i,j,k,l,r,x,y,z; string s; FOR(i,N_) C_[i][0]=C_[i][i]=1; for(i=1;i<N_;i++) for(j=1;j<i;j++) C_[i][j]=(C_[i-1][j-1]+C_[i-1][j])%mo; FOR(i,1010) { fact[i][0]=1; FOR(j,1001) fact[i][j+1]=fact[i][j]*i%mo; } cin>>N>>M; FOR(i,N) { cin>>W[i], mat[i][i]=W[i]; z=W[i]; for(x=1;x<=z;x++) { dp[z][x]=fact[x][z]; for(y=1;y<x;y++) { dp[z][x] -= C_[x][y] * dp[z][y] % mo; if(dp[z][x]<0) dp[z][x] += mo; } } } FOR(i,M) { cin>>I[i]>>J[i], I[i]--, J[i]--; mat[I[i]][J[i]]=min(W[I[i]],W[J[i]]); } FOR(z,N) FOR(x,N) FOR(y,N) mat[x][y] = max(mat[x][y], min(mat[x][z],mat[z][y])); ll ret=0; FOR(x,N) FOR(y,N) if(mat[x][y]>=W[y] && W[x]>=W[y]) ret +=dp[W[x]][W[y]]; cout<<ret%mo<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); solve(); return 0; }