#include using namespace std; typedef long long ll; typedef vector vi; typedef vector vl; typedef complex P; typedef pair pii; typedef pair pll; #define REP(i,n) for(ll i=0;i>=1; } return r; } // O(logx) ll mypow(ll a,ll x){ if(x==0)return 1; ll p = mypow(a,x/2); p = p*p%MOD; if(x&1) p = p*a%MOD; return p; } ll fact[1010]; ll ifact[1010]; ll comb(ll a,ll b){ if(a-b<0)return 0; return fact[a]*ifact[a-b]%MOD*ifact[b]%MOD; } ll zmemo[1010][1010]; // O(k) ll zensha(ll n,ll k){ if(zmemo[n][k])return zmemo[n][k]; ll ret = 0; REPR(i,k+1){ ll tmp = 1; if((k-i)%2==1)tmp = MOD-1; tmp = tmp*comb(k,i)%MOD; tmp = tmp*mypow(i,n)%MOD; ret = (ret+tmp)%MOD; } return zmemo[n][k]=ret; } int main(){ fact[0] = 1; REPR(i,1010) fact[i] = fact[i-1]*i%MOD; REP(i,1010) ifact[i] = inv(fact[i]); ll n,m; cin>>n>>m; vl w(n); REP(i,n) cin>>w[i]; vector G(n,vl(n,0)); REP(i,m){ ll x,y; cin>>x>>y; --x;--y; if(x==y)continue; G[x][y] = min(w[x],w[y]); } REP(i,n)G[i][i] = w[i]; // warshall floyd REP(k,n)REP(i,n)REP(j,n){ G[i][j] = max(G[i][j], min(G[i][k],G[k][j])); } ll result = 0; REP(src,n){ REP(to,n){ if(G[src][to]==w[to]){ result += zensha(w[src],w[to]); result %= MOD; } } } cout << result << endl; return 0; }