#include <bits/stdc++.h>

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

template<typename T> T& updMin(T& a, T const& b) { if (b < a) a = b; return a; }
template<typename T> T& updMax(T& a, T const& b) { if (a < b) a = b; return a; }

// ========================================================================= //

const int N = 3033;

int n, a[N];
int d[N][N];
int q, qx[N], qy[N];

int& getD(int x, int y) {
    if (x > y)
        swap(x, y);
    return d[x][y];
}

int main() {
    ios::sync_with_stdio(false);

    cin >> n >> q;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < q; ++i) {
        cin >> qx[i] >> qy[i];
        --qx[i];
        --qy[i];
    }

    int gg = (MOD + 1) / 2;

    int pow2 = 1;
    for (int num = q - 1; num >= 0; --num) {
        int p1 = qx[num], p2 = qy[num];
        if (p1 > p2)
            swap(p1, p2);

        int nd0 = 1;
        static int nd1[N], nd2[N];

        for (int i = 0; i < n; ++i) {
            if (i == p1 || i == p2)
                continue;
            if (i < p1)
                nd1[i] = (getD(i, p1) + getD(i, p2)) % MOD;
            else if (i < p2)
                nd1[i] = (1LL*MOD + getD(i, p1) + 1 - getD(i, p2)) % MOD;
            else
                nd1[i] = (getD(i, p1) + getD(i, p2)) % MOD;
            nd1[i] = (1LL * nd1[i] * gg) % MOD;
        }
        for (int i = 0; i < n; ++i) {
            if (i == p1 || i == p2)
                continue;
            if (i < p1)
                nd2[i] = (getD(i, p1) + getD(i, p2)) % MOD;
            else if (i < p2)
                nd2[i] = (1LL*MOD - getD(i, p1) + 1 + getD(i, p2)) % MOD;
            else
                nd2[i] = (getD(i, p1) + getD(i, p2)) % MOD;
            nd2[i] = (1LL * nd2[i] * gg) % MOD;
        }
        nd0 = (1LL * nd0 * gg) % MOD;

        d[p1][p2] = nd0;
        for (int i = 0; i < n; ++i)
            if (i != p1 && i != p2)
                getD(p1, i) = nd1[i];
        for (int i = 0; i < n; ++i)
            if (i != p1 && i != p2)
                getD(p2, i) = nd2[i];

        /*for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j)
                fprintf(stderr, "%4d", getD(i, j));
            fprintf(stderr, "\n");
        }
        fprintf(stderr, "\n");*/
        pow2 = (pow2 * 2) % MOD;
    }

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            d[i][j] = (1LL * d[i][j] * pow2) % MOD;

    int ans = 0;
    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j)
            if (a[i] < a[j])
                ans = (ans + getD(i, j)) % MOD;
            else if (a[i] > a[j])
                ans = (ans + 1LL*MOD + pow2 - getD(i, j)) % MOD;
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 35840