#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7 , inv2 = (mod+1)/2;
ll n,p=1,q,ans,a[3005],dp[3005][3005];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n>>q;
    for(ll i=1;i<=n;i++)cin>>a[i];
    for(ll i=1;i<=n;i++)for(ll j=1;j<=n;j++)dp[i][j]=a[i]>a[j];
    for(;q>0;q--){
        ll x,y;cin>>x>>y;
        for(ll i=1;i<=n;i++){
            if(i==x || i==y)continue;
            ll p = dp[x][i] + dp[y][i];
            ll q = dp[i][x] + dp[i][y];
            dp[x][i]=dp[y][i]=p*inv2%mod;
            dp[i][x]=dp[i][y]=q*inv2%mod;
        }
        ll r = dp[x][y] + dp[y][x];
        dp[x][y]=dp[y][x]=r*inv2%mod;
        p=(p*2)%mod;
    }
    for(ll i=1;i<=n;i++)for(ll j=i+1;j<=n;j++)ans=(ans + dp[i][j])%mod;
    ans = (ans * p)%mod;
    cout<<ans;
}