#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; } 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[1000]; ll comb(ll a,ll b){ if(a-b<0)return 0; return fact[a]*inv(fact[a-b])%MOD*inv(fact[b])%MOD; } ll zensha(ll n,ll 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 ret; } int main(){ fact[0] = 1; REPR(i,1000) fact[i] = fact[i-1]*i%MOD; ll n,m; cin>>n>>m; vl w(n); REP(i,n) cin>>w[i]; vl G[n]; REP(i,m){ ll x,y; cin>>x>>y; --x;--y; if(x==y)continue; G[x].push_back(y); } ll result = 0; REP(src,n){ vl flow(n,0); flow[src] = w[src]; priority_queue Q; Q.push(make_pair(flow[src],src)); vector used(n,false); while(!Q.empty()){ pll P = Q.top(); Q.pop(); ll f = P.first; ll u = P.second; if(used[u])continue; used[u] = true; REP(ed,G[u].size()){ ll v = G[u][ed]; if(flow[v]>=min(f,w[v]))continue; flow[v]=min(f,w[v]); Q.push(make_pair(flow[v],v)); } } REP(to,n){ if(flow[to]==w[to]){ result += zensha(w[src],w[to]); result %= MOD; } } } cout << result << endl; return 0; }