#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define pld pair <ld, ld>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >
#define cld complex <double>

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 3e3 + 100;
const ll mod = 1e9 + 7;

ll n, m, k, t;

ll C[maxn][maxn];

ll S[maxn][maxn];

ll A[maxn];

vector <pll> Q;

vector <ll> I;

inline ll step(ll a, ll x) {
    if (x == 0) {
        return 1;
    }
    if (x % 2 == 1) {
        return step(a, x - 1) * a % mod;
    }
    ll t = step(a, x / 2);
    return t * t % mod;
}

inline ll del(ll a, ll b) {
    return a * step(b, mod - 2) % mod;
}

ll geti(ll x) {
    return lower_bound(all(I), x) - I.begin();
}

int main() {
    pyshnapyshnakaa
    ll q, w, e, a, b, c;
    cin >> n >> k;
    ll r2 = del(1, 2);
    for (q = 0; q < n; q++) {
        cin >> A[q];
        I.pb(A[q]);
        // A[q]--;
        // C[q][A[q]]++;
    }
    sort(all(I));
    I.resize(unique(all(I)) - I.begin());
    for (q = 0; q < n; q++) {
        A[q] = geti(A[q]);
        // C[q][A[q]]++;
    }
    for (q = 0; q < n; q++) {
        for (w = 0; w < n; w++) {
            if (A[q] > A[w]) {
                // cout << q << " " << w << " Q W" << endl;
                C[q][w]++;
            }
        }
    }
    // cout << "C:" << endl;;
    // for (w = 0; w < n; w++) {
    //     for (e = 0; e < n; e++) {
    //         cout << C[w][e] << " ";
    //     }
    //     cout << endl;
    // }
    // cout << endl;
    for (q = 0; q < k; q++) {
        cin >> a >> b;
        a--; b--;
        Q.pb(mp(a, b));
        // cout << "A B " << a << " " << b << endl;
        for (w = 0; w < n; w++) {
            if (w == a || w == b) {
                continue;
            }
            C[w][a] = (C[w][a] + C[w][b]) % mod;
            C[a][w] = (C[a][w] + C[b][w]) % mod;
            C[w][b] = C[w][a];
            C[b][w] = C[a][w];

            C[w][a] = C[w][a] * r2 % mod;
            C[a][w] = C[a][w] * r2 % mod;
            C[w][b] = C[w][b] * r2 % mod;
            C[b][w] = C[b][w] * r2 % mod;;
        }
        ll sum = C[a][b] + C[b][a];
        C[a][b] = C[b][a] = sum;
        C[a][b] = C[a][b] * r2 % mod;
        C[b][a] = C[b][a] * r2 % mod;
        // swap(C[a][b], C[b][a]);
        // cout << "C:" << endl;;
        // for (w = 0; w < n; w++) {
        //     for (e = 0; e < n; e++) {
        //         cout << C[w][e] << " ";
        //     }
        //     cout << endl;
        // }
        // cout << endl;
        // for (w = 0; w < n; w)
    }
    ll ans = 0;
    for (q = 0; q < n; q++) {
        for (w = q + 1; w < n; w++) {
            ll dans = C[q][w];
            // ll dans = (C[q][w] * S[q - 1][w + 1]) % mod;
            ans += dans;
            ans %= mod;
        }
    }
    cout << ans * step(2, k) % mod;
    return 0;
}


Measured memory_bytes: 76436