//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}
 
int n, m, k;
int pw[N];
int last[N][N];
int dp[N][N];
int was[N][N];
int laz[N][N];
int a[N];

vector < pair<int, int> > sav;


void add (int a, int b, int c) {
	laz[a][b] += c;
	if(laz[a][b] >= mod) laz[a][b] -= mod;
	if(!was[a][b]) {
		sav.pb({a, b});
		was[a][b] = 1;
	}
}

int timer;
void relax (int a, int b) {
	dp[a][b] = dp[a][b] * (ll)pw[timer-last[a][b]] % mod;
	last[a][b] = timer;
}

void push () {
	for (auto it : sav) {
		int i, j;
		tie(i, j) = it;
		dp[i][j] += laz[i][j];
		if (dp[i][j] >= mod) dp[i][j] -= mod;
		was[i][j] = laz[i][j] = 0;
	}
	sav.clear();
}

void upd(int x, int y) { 
	timer++;
	for(int i = 1; i <= n; i++) {
		last[i][x]++;
		last[x][i]++;
		last[i][y]++;
		last[y][i]++;
	}
	last[x][y] -= 1;
	last[y][x] -= 1;
}

int main () {
	SpeedForce;
	
	cin >> n >> m;
	pw[0] = 1;
	for (int i = 1; i < N; ++i)
		pw[i] = pw[i-1] * 2 % mod;
	
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j) if (a[j] < a[i]) {
			add(i, j, 1);
		}

   	push();


   	for (int i = 1; i <= m; ++i) {
   		int x, y;
   		cin >> x >> y;
   		for (int j = 1; j <= n; ++j) {
   			relax(j, x);
   			relax(j, y);
   			relax(x, j);
   			relax(y, j);

   			if(j != y) {
   				add(j, y, dp[j][x]);
   				add(y, j, dp[x][j]);
   			}

   			if (j != x) {
   				add (j, x, dp[j][y]);
   				add (x, j, dp[y][j]);
   			}
   		}
   		add(x, y, dp[y][x]);
   		add(y, x, dp[x][y]);

   		push();
   		upd (x, y);
   	}

   	int ans = 0;
   	for (int i = 1; i <= n; ++i)
   		for (int j = i+1; j <= n; ++j) {
   			relax(i, j);
   			ans += dp[i][j];
   			if(ans >= mod) ans -= mod;
   		}

	cout << ans << '\n';

	return Accepted;
}

// B...a

Measured memory_bytes: 184924