#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define mind(a,b) (a>b?b:a) #define maxd(a,b) (a>b?a:b) #define absd(x) (x<0?-(x):x) #define pow2(x) ((x)*(x)) #define rep(i,n) for(int i=0; i=0; --i) #define repl(i,s,n) for(int i=s; i<=n; ++i) #define replr(i,s,n) for(int i=n; i>=s; --i) #define repf(i,s,n,j) for(int i=s; i<=n; i+=j) #define repe(e,obj) for(auto e : obj) #define SP << " " << #define COL << " : " << #define COM << ", " << #define ARR << " -> " << #define PNT(STR) cout << STR << endl #define POS(X,Y) "(" << X << ", " << Y << ")" #define DEB(A) " (" << #A << ") " << A #define DEBREP(i,n,val) for(int i=0; i P; //typedef pair P; typedef pair PI; typedef pair IP; typedef pair PP; typedef priority_queue, greater

> pvqueue; #define W 1003 #define N 203 #define MOD 1000000007 ll n, m; ll w[N]; ll e[N][N]; ll memo[W][W]; ll c[W][W]; ll fact[W]; ll comb(ll n, ll k) { if(c[n][k]!=-1) return c[n][k]; if(n < 2*k) k = n-k; if(n==k || k==0) return 1; return c[n][k] = (comb(n-1, k-1) + comb(n-1, k)) % MOD; } ll fcnt(ll wi, ll wj) { if(wi < wj) return 0; if(memo[wi][wj]!=-1) return memo[wi][wj]; if(wj==1) return 1; ll r = 0; repl(i, 1, wi) { r = (r + (fcnt(wi-i, wj-1)*comb(wi, i))%MOD ) % MOD; } return memo[wi][wj] = r; } int main() { cin >> n >> m; rep(i, n) cin >> w[i]; rep(i, m) { ll s, t; cin >> s >> t; --s; --t; e[s][t] = mind(w[s], w[t]); } rep(i, n) e[i][i] = 1; rep(k, n) rep(i, n) rep(j, n) { if(e[i][k] != INF && e[k][j] != INF) { ll r = mind(e[i][k], e[k][j]); e[i][j] = maxd(e[i][j], r); } } rep(i, W) rep(j, W) memo[i][j] = c[i][j] = -1; fact[0] = 1; rep(i, W-1) { fact[i+1] = ((i+1)*fact[i]) % MOD; } ll ans = 0; rep(i, n) { rep(j, n) { if(i==j) { ans = (ans + fact[w[i]]) % MOD; } else if(w[i] >= w[j] && e[i][j]!=INF && e[i][j]>=w[j]) { ans = (ans + fcnt(w[i], w[j])) % MOD; } } } cout << ans << endl; return 0; }