#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 31;
const int mod = 1e9 + 7;
int n, m;
vector<int> depth(maxn), ke[maxn];
vector<int> node_on_depth(maxn, 0);
vector<int> edge_on_depth(maxn, 0);
int max_depth;
int hehepow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
/*
node_on_depth : so luong node cung do cao
edge_on_depth : so luong canh cung do cao
*/
// chinh xac
void init(){
for(int i = 1;i <= n;i++){
node_on_depth[depth[i]]++;
}
for(int u = 1;u <= n;u++){
for(auto v : ke[u]){
if(depth[u] == depth[v] && u < v)
edge_on_depth[depth[u]]++;
}
}
}
// kiem tra co dap an hay khong
bool solvable(){
for(int i = 2;i <= n;i++){
if(depth[i] == 0) return false;
}
for(int i = 1;i <= max_depth;i++){
if(node_on_depth[i] == 0) return false;
}
for(int i = 1;i <= n;i++){
for(auto j : ke[i]){
if(abs(depth[i] - depth[j]) > 1) return false;
}
}
return true;
}
// ham solve
int solve(){
if(solvable() == false) return 0;
int ans = 1;
// xet cac canh cung tang
for(int i = 1;i <= max_depth;i++){
if(node_on_depth[i] > 1){
ans = 1ll * ans * hehepow(2, node_on_depth[i] * (node_on_depth[i] - 1) / 2 - edge_on_depth[i], mod) % mod;
// cout << i << " " << ans << endl;
}
}
// xet cac canh khac tang
for(int u = 2;u <= n;u++){
int edge_on = 0;
// v la cha u
for(int v : ke[u]){
if(depth[v] == depth[u] - 1) edge_on++;
}
// cout << "node " << u << " : ";
int edge_remain = node_on_depth[depth[u] - 1] - edge_on;
// cout << edge_remain << " " << edge_on << " ";
if(edge_on){
ans = 1ll * ans * hehepow(2, edge_remain, mod) % mod;
}
else{
ans = 1ll * ans * (hehepow(2, edge_remain, mod) - 1) % mod;
}
// cout << "ans : " << ans << endl;
}
return ans;
}
void check(){
for(int i = 1;i <= n;i++){
cout << "node_on_depth " << i << " : " << node_on_depth[i] << endl;
}
cout << endl;
for(int i = 1;i <= n;i++){
cout << "edge_on_depth " << i << " : " << edge_on_depth[i] << endl;
}
}
int main() {
cin >> n >> m;
for(int i = 1;i <= n;i++) cin >> depth[i];
for(int i = 1;i <= n;i++){
max_depth = max(max_depth, depth[i]);
}
for(int i = 1;i <= m;i++){
int u, v;
cin >> u >> v;
ke[u].push_back(v);
ke[v].push_back(u);
}
init();
// check();
cout << solve() << endl;
}