#include <bits/stdc++.h>

typedef long long ll;
const int N = 3054, mod = 1000000007, iv2 = (mod + 1) / 2;

int n, q;
int a[N], f[N][N];

ll PowerMod(ll a, int n, ll c = 1) {for (; n; n >>= 1, a = a * a % mod) if (n & 1) c = c * a % mod; return c;}

inline int half(int x) {return x = (x >> 1) + (-(x & 1) & (iv2 - mod)), x + (x >> 31 & mod);;}

int main() {
	int i, j, u, v; ll I = 0;
	scanf("%d%d", &n, &q);
	for (i = 1; i <= n; ++i) scanf("%d", a + i);
	for (i = 1; i <= n; ++i)
		for (j = 1; j <= n; ++j)
			f[i][j] = a[i] > a[j];
	for (i = 0; i < q; ++i) {
		scanf("%d%d", &u, &v), f[u][v] = f[v][u] = half(f[u][v] + f[v][u]);
		for (j = 1; j <= n; ++j) if (j != u && j != v)
			f[u][j] = f[v][j] = half(f[u][j] + f[v][j]),
			f[j][u] = f[j][v] = half(f[j][u] + f[j][v]);
	}
	for (i = 1; i <= n; ++i) I += std::accumulate(f[i] + i, f[i] + (n + 1), 0ll);
	printf("%d\n", (int)PowerMod(2, q, I % mod));
	return 0;
}