#include #include #include #include #include #include #include #define N_MAX 2002 using namespace std; typedef long long ll; ll inv[N_MAX],fac[N_MAX],finv[N_MAX]; ll pow[N_MAX][N_MAX]; const ll MOD = 1000000007; void init(){ fac[0]=fac[1]=1; finv[0]=finv[1]=1; inv[1]=1; for(int i=2;i G[200]; int w[200]; int N, M; bool used[200]; void clear(){ for(int i = 0; i < N; i++) used[i] = false; } ll ans; ll calc(int n, int m){ ll ret = 0; // i個使わない for(int i = 0; i < m; i++){ int sgn = i%2 == 0 ? 1 : -1; ret += (sgn*comb(m, i)*pow[m-i][n])%MOD; ret %= MOD; } // cout << "calc(" << n << ", " << m << ") = " << (ret+MOD)%MOD << endl; return (ret+MOD)%MOD; } void dfs(int v,int r){ used[v] = true; ans += calc(w[v], w[r]); ans %= MOD; for(int to : G[v]){ if(!used[to] && w[to] >= w[r]) dfs(to, r); } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; init(); cin >> N >> M; for(int i = 0; i < N; i++) cin >> w[i]; for(int i = 0; i < M; i++){ int u, v; cin >> u >> v; u--; v--; G[v].push_back(u); } for(int i = 0; i < N; i++){ dfs(i, i); clear(); } cout << ans << endl; }