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

const int MOD = 1e9 + 7, INV = MOD + 1 >> 1, N = 3333;

int f[N][N], a[N], g[N], h[N], Q, n;

int main(void) {
  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++) {
      if(a[j] < a[i]) {
	f[i][j] = 1;
      }
      if(a[j] > a[i]) {
	f[j][i] = 1;
      }
    }
  }
  long long coef = 1;
  while(Q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    for(int i = 1; i <= n; i++) {
      g[i] = 1LL * (f[x][i] + f[y][i]) * INV % MOD;
      h[i] = 1LL * (f[i][y] + f[i][x]) * INV % MOD;
    }
    for(int i = 1; i <= n; i++) {
      if(i == x || i == y) {
	continue;
      }
      f[x][i] = f[y][i] = g[i];
      f[i][y] = f[i][x] = h[i];
    }
    f[x][y] = f[y][x] = 1LL * (f[x][y] + f[y][x]) * INV % MOD;
    coef = coef * 2 % MOD;
  }
  int ans = 0;
  for(int i = 1; i < n; i++) {
    for(int j = i + 1; j <= n; j++) {
      ans = (ans + f[i][j]) % MOD;
    }
  }
  
  cout << ans * coef % MOD << endl;
}
