#include <stdio.h>

const long long mod = 1000000007;
const long long inv2 = (mod + 1) / 2;

int N,Q,A[3030],C[3030][3030];

int main()
{
	scanf ("%d %d",&N,&Q);

	for (int i=1;i<=N;i++) scanf ("%d",&A[i]);
	for (int i=1;i<=N;i++) for (int j=1;j<=N;j++) C[i][j] = A[i] > A[j];

	long long mul = 1;
	for (int q=1;q<=Q;q++){
		int x,y; scanf ("%d %d",&x,&y);
		for (int i=1;i<=N;i++) if (i != x && i != y){
			int p = C[x][i] + C[y][i];
			int q = C[i][x] + C[i][y];
			C[x][i] = C[y][i] = p * inv2 % mod;
			C[i][x] = C[i][y] = q * inv2 % mod;
		}
		int r = C[x][y] + C[y][x];
		C[x][y] = C[y][x] = r * inv2 % mod;
		mul = mul * 2 % mod;
	}

	long long ans = 0;
	for (int i=1;i<=N;i++) for (int j=i+1;j<=N;j++) ans = (ans + C[i][j] * mul) % mod;
	printf ("%lld\n",ans);
	
	return 0;
}