#include<cstdio>
#include<cstdlib>
#include<cstring>

using namespace std;

const int maxn=3010;
const int mo=1000000007;

int n,m,f[maxn][maxn],z[maxn];

int mul(int a,int b)
{
	int ans=1;
	while (b)
	{
		if (b&1) ans=1ll*ans*a%mo;
		a=1ll*a*a%mo;
		b>>=1;
	}
	return ans;
}

int main()
{
	scanf("%d%d",&n,&m);
	for (int a=1;a<=n;a++)
		scanf("%d",&z[a]);
	for (int a=1;a<=n;a++)
		for (int b=1;b<=n;b++)
			f[a][b]=(z[a]<z[b]);
	int div2=mul(2,mo-2);
	for (int a=1;a<=m;a++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		if (x==y) continue;
		f[x][y]=f[y][x]=(0ll+f[x][y]+f[y][x])*div2%mo;
		for (int b=1;b<=n;b++)
			if (b!=x && b!=y)
			{
				f[b][x]=f[b][y]=(0ll+f[b][x]+f[b][y])*div2%mo;
				f[x][b]=f[y][b]=(0ll+f[x][b]+f[y][b])*div2%mo;
			}
	}
	int ans=0;
	for (int a=1;a<=n;a++)
		for (int b=a+1;b<=n;b++)
		{
			ans += f[b][a];
			if (ans>=mo) ans-=mo;
		}
	printf("%d\n",1ll*ans*mul(2,m)%mo);

	return 0;
}
