#include <bits/stdc++.h>
using namespace std;

#define cerr cout
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
template<int MOD>
struct ModInt {
    static const int Mod = MOD;
    unsigned x;
    ModInt() : x(0) {}
    ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
    ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
    int get() const { return (int)x; }
    bool operator==(ModInt that) const {return this->x == that.x;}

    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt &operator^=(ModInt<MOD - 1> that) { *this = that; return *this; }

    friend ostream& operator<<(ostream& out, const ModInt& yo) { out << yo.x; return out; }

    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

    ModInt operator^(ModInt<MOD - 1> that) const {
    	ModInt ans = 1;
    	ModInt a = *this;
    	while (that.x > 0) {
    		if (that.x & 1) ans = ans * a;
    		a = a * a;
    		that.x >>= 1;
    	}
    	return ans;
    }

    ModInt inverse() const {
        signed a = x, b = MOD, u = 1, v = 0;
        while (b) {
            signed t = a / b;
            a -= t * b; std::swap(a, b);
            u -= t * v; std::swap(u, v);
        }
        if (u < 0) u += Mod;
        ModInt res; res.x = (unsigned)u;
        return res;
    }
};
template<int MOD> string to_string(ModInt<MOD> x) {return to_string(x.x);}
typedef ModInt<inf> mint;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);

	int n, q; cin >> n >> q; vi a(n);
	FOR (i, 0, n - 1) cin >> a[i];

	vector<vector<mint>> p(n);
	FOR (i, 0, n-1) {
		FOR (j, 0, n-1) {
			p[i].emplace_back(a[i] > a[j]);
		}
	}


	mint ti = mint(1) / 2;

	FOR (it, 1, q) {
		int x, y; cin >> x >> y; --x, --y;
		
		FOR (i, 0, n - 1) if (i != x and i != y) {
			p[i][y] = p[i][x] = ti * (p[i][x] + p[i][y]);
			p[y][i] = p[x][i] = ti * (p[x][i] + p[y][i]); 
		}
		p[x][y] = p[y][x] = ti * (p[x][y] + p[y][x]);
	}

	mint ans = 0;

	FOR (i, 0, n - 1) FOR (j, i+1, n-1) ans += p[i][j];
	cout << ans * (mint(2) ^ q);
	
	return 0;
}

Measured memory_bytes: 49768