using namespace std;
#include <iostream>
#include <cstring>
#include <vector>
#include <fstream>
#define mod 1000000007
long long ans = 1;
struct matrix {
long long a[20][20];
matrix() {memset(a,0,sizeof(a));}
matrix(int v[20][20]) {memcpy(a,v,sizeof(a));}
void addE() {for(int i = 0;i < 20;i++) a[i][i]++;}
matrix operator *(const matrix &b) {
matrix ret;
for(int i = 0;i < 20;i++)
for(int j = 0;j < 20;j++)
for(int k = 0;k < 20;k++)
ret.a[i][k]=(ret.a[i][k] + a[i][j] * 1LL * b.a[j][k]) % mod;
return ret;
}
};
matrix fastpow(matrix x,long long a) {
matrix ret;ret.addE();
while(a) {
if(a & 1) ret = ret*x;
x = x * x;
a >>= 1;
}
return ret;
}
int N,M,K;
long long arr[20];
vector<int> edges[100];
bool dp[20];
void solve(int n) {
if(n == 0) return;
if(dp[n]) return;
dp[n] = 1;
bool isChild[20];
memset(isChild,0,sizeof(isChild));
for(int i = 0;i < edges[n].size();++i) {
int next = edges[n][i];
isChild[next] = true;
solve(next);
}
matrix mval[20];
mval[0].a[0][0] = isChild[0];
for(int i = 1;i <= n;++i) {
long long times = arr[i] / arr[i - 1];
mval[i] = fastpow(mval[i - 1],times);
for(int j = 0;j <= i;++j) {
if(isChild[i]) {
mval[i].a[i][j]++;
if(mval[i].a[i][j] >= mod) mval[i].a[i][j] -= mod;
}
}
}
long long res = 0;
for(int i = 0;i <= n;++i) {
res += mval[n].a[i][0];
if(res >= mod) res -= mod;
}
ans = (ans * res) % mod;
return;
}
int main() {
cin >> N >> M;
for(int i = 0;i < N;++i) {
cin >> arr[i];
}
for(int i = 0;i < M;++i) {
int a,b;
cin >> a >> b;
a--;b--;
if(arr[a] > arr[b]) {
swap(a,b);
}
edges[b].push_back(a);
}
solve(N - 1);
cout << ans << endl;
}
dXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNs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