#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)((a).size()))
#define watch(x) cout << (#x) << " = " << (x) << endl;

const double PI = 2 * acos(0.0);

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template<class T>
ostream & operator << (ostream &out, vector<T> &a) {
    out << "{";
    fori (i, SZ(a))
        out << a[i] << vector<string>{", ", "}"}[i + 1 == SZ(a)];
    return out;
}

void smain();

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


#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\n";
    cout << "TOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
}

int n, q;
const int N = 3003;
const ll M = 1e9 + 7;
int a[N];

ll pw(ll a, ll n) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret = (ret * a) % M;
        a = (a * a) % M;
        n >>= 1;
    }
    return ret;
}

ll pw2[N];

int dp[N][N];

pii queries[N];

void smain() {
    pw2[0] = 1;
    for (int i = 1; i < N; ++i) pw2[i] = pw2[i - 1] * 2 % M;
    cin >> n >> q;
    fori (i, n) cin >> a[i];
    fori (i, q) {
        cin >> queries[i].first >> queries[i].second;
        queries[i].first--, queries[i].second--;
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < i; ++j) {
            dp[i][j] = 1;
        }
    }
    ll inv2 = pw(2, M - 2);
    for (int t = q - 1; t >= 0; --t) {
        int a = queries[t].first, b = queries[t].second;
        vector<pair<pii, int>> upd;
        for (int j = 0; j < n; ++j) if (j != a && j != b) {
            upd.push_back({{j, b}, dp[j][a] * inv2 % M});
            upd.push_back({{b, j}, dp[a][j] * inv2 % M});

            upd.push_back({{j, a}, dp[j][b] * inv2 % M});
            upd.push_back({{a, j}, dp[b][j] * inv2 % M});
        }

        upd.push_back({{a, b}, dp[b][a] * inv2 % M});
        upd.push_back({{b, a}, dp[a][b] * inv2 % M});

        for (auto x : upd) {
            dp[x.first.first][x.first.second] = (dp[x.first.first][x.first.second] * inv2 + x.second) % M;
        }

    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (a[i] < a[j]) ans = (ans + dp[i][j]) % M;
            else if (a[i] > a[j]) ans = (ans + 1 - dp[i][j] + M) % M;
        }
    }
    ans = (ans * pw2[q]) % M;
    cout << ans;
}

Measured memory_bytes: 35984