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

const int N = 3005 , mod = 1e9 + 7 ;
long long inv2 = 5e8 + 4 , mul = 1;
int n , q , a[N] , p[N][N] , ans = 0;

int main() {
    scanf("%d %d" , &n , &q);
    for(int i = 1 ; i <= n ; ++i) scanf("%d" , a + i);
    for(int i = 1 ; i <= n ; ++i)
        for(int j = 1 ; j <= n ; ++j) p[i][j] = (a[i] < a[j]);
    while(q--) {
        mul = (mul << 1) % mod;
        int a , b;
        scanf("%d %d" , &a , &b);
        for(int i = 1 ; i <= n ; ++i)
            if(i != a && i != b) {
                p[i][b] = p[i][a] = (p[i][a] * inv2 + p[i][b] * inv2) % mod;
                p[b][i] = p[a][i] = (p[b][i] * inv2 + p[a][i] * inv2) % mod;
            }
        p[a][b] = p[b][a] = (p[a][b] * inv2 + p[b][a] * inv2) % mod;
    }
    for(int i = 1 ; i <= n ; ++i)
        for(int j = i + 1 ; j <= n ; ++j) ans = (ans + mul * p[j][i]) % mod;
    printf("%d\n" , ans);
    return 0;
}