/************************************************
 * Au: Hany01
 * Email: hany01dxx@gmail.com & hany01@foxmail.com
 * Inst: Yali High School
************************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
#define Rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define X first
#define Y second
#define PB(a) push_back(a)
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((int)(a).size())
#define ALL(a) a.begin(), a.end()
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 wozenmezhemecaia

template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

template <typename T> inline T read() {
	register T _, __; register char c_;
    for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
    for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}
//EOT


const int MAXN = 3005, MOD = 1e9 + 7;

int sum[MAXN], ls[MAXN], lss, n, m, sm[MAXN];

inline int fpm(int a, int b = MOD - 2) {
	register int ans = 1;
	for ( ; b; b >>= 1, a = (LL)a * a % MOD)
		if (b & 1) ans = (LL)ans * a % MOD;
	return ans;
}

int f[MAXN][MAXN], res[MAXN][MAXN], a[MAXN];
int inv = (MOD + 1) / 2;

void solve() {
	int u, v;
	For(i, 1, n) For(j, i + 1, n) {
		if (a[i] < a[j]) f[i][j] = 1;
		if (a[j] < a[i]) f[j][i] = 1;
	}
	For(i, 1, m) {
		u = read<int>(), v = read<int>();
		For(i, 1, n) res[i][u] = res[i][v] = res[u][i] = res[v][i] = 0;
		For(i, 1, n) if (i ^ u && i ^ v) {
			(res[i][v] += (f[i][u] + f[i][v]) % MOD) %= MOD;
			(res[i][u] += (f[i][u] + f[i][v]) % MOD) %= MOD;
			(res[u][i] += (f[u][i] + f[v][i]) % MOD) %= MOD;
			(res[v][i] += (f[u][i] + f[v][i]) % MOD) %= MOD;
		}
		res[u][v] = res[v][u] = (f[u][v] + f[v][u]) % MOD;
		For(i, 1, n) {
			f[i][u] = 1ll * res[i][u] * inv % MOD;
			f[i][v] = 1ll * res[i][v] * inv % MOD;
			f[u][i] = 1ll * res[u][i] * inv % MOD;
			f[v][i] = 1ll * res[v][i] * inv % MOD;
		}
	}
	int ans = 0;
	For(i, 1, n) For(j, 1, i - 1)
		(ans += f[i][j]) %= MOD;
	ans = (LL)ans * fpm(2, m) % MOD;
	cout << ans << endl;
}

int main() {
#ifdef hany01
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
#endif

	n = read<int>(), m = read<int>();
	For(i, 1, n) a[i] = read<int>();

	solve();

	/*For(i, 1, n) ls[i] = a[i] = read<int>();
	sort(ls + 1, ls + 1 + n), lss = unique(ls + 1, ls + 1 + n) - ls - 1;
	For(i, 1, n) {
		a[i] = lower_bound(ls + 1, ls + 1 + lss, a[i]) - ls;
		f[i][i] = 1;
	}
	int inv = fpm(2);
	For(i, 1, q) {
		int x = read<int>(), y = read<int>();
		For(j, 1, n) f[j][x] = f[j][y] = (LL)(f[j][x] + f[j][y]) * inv % MOD;
	}

	int ans = 0;
	For(i, 1, n) {
		For(j, 1, n) (ans += (LL)sum[a[j] + 1] * f[j][i]) %= MOD;
		For(j, 1, n) sm[j] = 0;
		For(j, 1, n) (sm[a[j]] += f[j][i]) %= MOD;
		Fordown(j, n, 1) (sm[j] += sm[j + 1]) %= MOD;
		For(j, 1, n) (sum[j] += sm[j]) %= MOD;
	}
	printf("%lld\n", (LL)ans * fpm(2, q) % MOD);*/

	return 0;
}

Measured memory_bytes: 70784