#include<iostream>
#include<algorithm>
#define int long long
const int mod=1e9+7;
const int N=3e3+2;
using namespace std;
int dp[N][N],ar[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,q,m,ans=0,damn=1,prob=(mod+1)/2;
	cin>>n>>q;
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			if(ar[i]>ar[j]){
				dp[i][j]=1;
			}
		}
	}
	for(i=1;i<=q;i++){
		damn*=2;
		if(damn>=mod){
			damn-=mod;
		}
		cin>>j>>k;
		for(l=1;l<=n;l++){
			if(j!=l&&k!=l){
				m=dp[j][l];
				dp[j][l]=(dp[j][l]+dp[k][l])*prob;
				dp[j][l]%=mod;
				dp[k][l]=(m+dp[k][l])*prob;
				dp[k][l]%=mod;
				m=dp[l][k];
				dp[l][k]=(dp[l][k]+dp[l][j])*prob;
				dp[l][j]=(m+dp[l][j])*prob;
				dp[l][k]%=mod;
				dp[l][j]%=mod;
			}	
		}
		dp[j][k]=dp[k][j]=(dp[j][k]+dp[k][j])*prob;
		dp[j][k]%=mod;
		dp[k][j]%=mod;
	}
	//cout<<dp[1][3]<<endl;
	for(i=1;i<=n;i++){
		for(j=i+1;j<=n;j++){
			//cout<<i<<' '<<j<<' '<<dp[i][j]<<endl;
			ans+=dp[i][j];
			if(ans>=mod){
				ans-=mod;
			}
		}
	}
	cout<<(ans*damn)%mod;
}