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

typedef tuple<int, int, long long> iii;

const long long MOD = 1e9+7;

int A[3005];

int X[3005];
int Y[3005];

long long dp[3005][3005]; // probability that A_x > A_y after random subset of Q operations in input

long long modpow(int a, int b){
    if(b == 0){
        return 1;
    }else if(b == 1){
        return a%MOD;
    }else{
        long long temp = modpow(a, b/2);
        if(b%2 == 0){
            return temp*temp%MOD;
        }else{
            return ((temp*temp)%MOD*a)%MOD;
        }
    }
}

int main(){
    int N, Q;
    scanf("%d%d", &N, &Q);

    for(int i = 0; i < N; i ++){
        scanf("%d", &A[i]);
    }

    for(int i = 0; i < Q; i ++){
        scanf("%d%d", &X[i], &Y[i]);
        X[i]--; Y[i]--;
    }

    for(int i = 0; i < N; i ++){
        for(int j = 0; j < N; j ++){
            dp[i][j] = A[j] < A[i];
        }
    }

    const long long HALF = modpow(2, MOD-2);
    int swap1[2];
    for(int k = 0; k < Q; k ++){
        vector<iii> changes;
        swap1[0] = X[k]; swap1[1] = Y[k];
        for(int i: swap1){
            for(int j = 0; j < N; j ++){
                if(i == j){continue;}
                // 50% chance no swap, 50% chance got swap
                if(i == X[k] && j == Y[k]){
                    changes.push_back(iii(i, j, (dp[i][j]*HALF + dp[j][i]*HALF)%MOD));
                }else if(j == X[k] && i == Y[k]){
                    changes.push_back(iii(i, j, (dp[i][j]*HALF + dp[j][i]*HALF)%MOD));
                }else if(i == X[k]){
                    changes.push_back(iii(i, j, (dp[i][j]*HALF + dp[Y[k]][j]*HALF)%MOD));
                }else if(j == X[k]){
                    changes.push_back(iii(i, j, (dp[i][j]*HALF + dp[i][Y[k]]*HALF)%MOD));
                }else if(i == Y[k]){
                    changes.push_back(iii(i, j, (dp[i][j]*HALF + dp[X[k]][j]*HALF)%MOD));
                }else if(j == Y[k]){
                    changes.push_back(iii(i, j, (dp[i][j]*HALF + dp[i][X[k]]*HALF)%MOD));
                }
            }
        }
        for(int i = 0; i < N; i ++){
            for(int j: swap1){
                if(i == j){continue;}
                // 50% chance no swap, 50% chance got swap
                if(i == X[k] && j == Y[k]){
                    changes.push_back(iii(i, j, (dp[i][j]*HALF + dp[j][i]*HALF)%MOD));
                }else if(j == X[k] && i == Y[k]){
                    changes.push_back(iii(i, j, (dp[i][j]*HALF + dp[j][i]*HALF)%MOD));
                }else if(i == X[k]){
                    changes.push_back(iii(i, j, (dp[i][j]*HALF + dp[Y[k]][j]*HALF)%MOD));
                }else if(j == X[k]){
                    changes.push_back(iii(i, j, (dp[i][j]*HALF + dp[i][Y[k]]*HALF)%MOD));
                }else if(i == Y[k]){
                    changes.push_back(iii(i, j, (dp[i][j]*HALF + dp[X[k]][j]*HALF)%MOD));
                }else if(j == Y[k]){
                    changes.push_back(iii(i, j, (dp[i][j]*HALF + dp[i][X[k]]*HALF)%MOD));
                }
            }
        }
        for(iii temp: changes){
            int i = get<0>(temp);
            int j = get<1>(temp);
            dp[i][j] = get<2>(temp);
        }
    }

    long long ans = 0;
    for(int i = 0; i < N; i ++){
        for(int j = i+1; j < N; j ++){
            ans += dp[i][j];
        }
    }
    ans %= MOD;
    printf("%lld", ans*modpow(2, Q)%MOD);
    return 0;
}

Measured memory_bytes: 71168