#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define HALF 500000004

int n, m, x[3005];
long long f[3005][31005], ans, mul = 1;

int ta, tb;

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%d", x + i);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			f[i][j] = x[i] < x[j];
	while (m--) {
		mul = (mul << 1) % MOD;
		scanf("%d%d", &ta, &tb);
		ta--;
		tb--;
		f[ta][tb] = f[tb][ta] = HALF * (f[ta][tb] + f[tb][ta]) % MOD;
		for (int i = 0; i < n; i++)
			if (i != ta && i != tb) {
				f[i][ta] = f[i][tb] = HALF * (f[i][ta] + f[i][tb]) % MOD;
				f[ta][i] = f[tb][i] = HALF * (f[ta][i] + f[tb][i]) % MOD;
			}
	}
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
			ans += f[j][i];
	printf("%lld\n", ans % MOD * mul % MOD);
	return 0;
}
