#include<bits/stdc++.h>
#define N 3005
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int n,q,a[N],x,y;
int now = 1,las = 0;
ll f[N][N],inv2;
ll qp(ll a,ll b) { ll ret = 1; for(;b;b>>=1,a = a * a % mod) if(b & 1) ret = ret * a % mod; return ret; }


int main()
{
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;++i) scanf("%d",a + i);
	inv2 = qp(2,mod - 2);
	ll qpn = qp(2,q);
	for(int i=1;i<=n;++i)
	  for(int j=1;j<=n;++j)
	    if(a[i] > a[j]) f[i][j] = 1;
	while(q--)
	{
		scanf("%d%d",&x,&y);
		swap(now,las);
		for(int i=1;i<=n;++i) 
		{
			if(i == x || i == y) continue;
			f[i][x] = f[i][y] = (f[i][x] + f[i][y]) % mod * inv2 % mod;
			f[x][i] = f[y][i] = (f[x][i] + f[y][i]) % mod * inv2 % mod;
		}
		f[y][x] = f[x][y] = (f[x][y] + f[y][x]) % mod * inv2 % mod;
	}
	ll ans = 0;
	for(int i=1;i<=n;++i)
	  for(int j=i + 1;j<=n;++j)
	     ans = (ans + f[i][j] * qpn % mod) % mod;
	cout<<ans<<endl;
	return 0;
}