#include<bits/stdc++.h>
using namespace std;
const int maxn=3e3+10;
const int mod=1e9+7,inv2=(mod+1)/2;
int n,m;
int dp[maxn][maxn],val[maxn],tot=1;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&val[i]);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)if(i!=j)dp[i][j]=val[i]<val[j];
	while(m--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		dp[x][y]=dp[y][x]=(dp[x][y]+dp[y][x])*1LL*inv2%mod;
		for(int i=1;i<=n;i++)
		{
			if(i==x||i==y)continue;
			dp[i][x]=dp[i][y]=(dp[i][x]+dp[i][y])*1LL*inv2%mod;
			dp[x][i]=dp[y][i]=(dp[x][i]+dp[y][i])*1LL*inv2%mod;
		}
		tot=tot*1LL*2%mod;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	for(int j=1;j<i;j++)ans+=dp[i][j]*1LL*tot%mod,ans%=mod;
	printf("%d\n",ans);

}