#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) using namespace std; typedef long long int ll; typedef vector VI; typedef vector VL; typedef pair PI; const ll mod = 1e9 + 7; ll powmod(ll a, ll e) { ll sum = 1; ll cur = a; while (e > 0) { if (e % 2) { sum = sum * cur % mod; } cur = cur * cur % mod; e /= 2; } return sum; } ll count_surj(int n, int k) { if (n < k) { return 0; } ll sum = 0; ll comb = 1; REP(i, 0, n) { sum += (powmod(k - i, n) * comb % mod) * (i % 2 == 0 ? 1 : mod - 1); sum %= mod; comb = comb * (k - i) % mod; comb = comb * powmod(1 + i, mod - 2) % mod; } return sum; } int main(void){ int n, m; cin >> n >> m; VI w(n); REP(i, 0, n) { cin >> w[i]; } vector e; REP(i, 0, m) { int u, v; cin >> u >> v; u--; v--; e.push_back(PI(u, v)); } // O(nm)-time ll tot = 0; REP(i, 0, n) { // retain A_k s.t. w_k >= w_i vector edges(n); for (PI uv : e) { int u = uv.first; int v = uv.second; if (w[u] >= w[i] && w[v] >= w[i]) { edges[v].push_back(u); } } // Vertices reachable to i VI reach(n, false); queue que; que.push(i); while (not que.empty()) { int v = que.front(); que.pop(); if (reach[v]) { continue; } reach[v] = true; REP(j, 0, edges[v].size()) { int w = edges[v][j]; que.push(w); } } REP(j, 0, n) { if (reach[j]) { tot += count_surj(w[j], w[i]); tot %= mod; } } } cout << tot << endl; }