#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
  constexpr bool operator==(const modint rhs) noexcept{
  return (*this).value()==rhs.value();
  }
  inline constexpr bool operator!=(const modint rhs) noexcept{
  return !(*this==rhs);
  }
};
#define MOD 1000000007
#define MOD 1000000007

long long mod_pow(long long a,long long b)
{
    a %= MOD;
    long long res = 1;
    while(b){
        if(b & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

modint<mod> pow(modint<mod> rhs,long long k) noexcept{
  ll exp = k;
  modint<mod> p = 1;
  while (exp) {
    if (exp % 2) {
      p *= rhs;
    }
    rhs *= rhs;
    exp /= 2;
  }
  return p;
}
int main(){
    int n,q;
    cin >> n >> q;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int>x(q),y(q);
    rep(i,q){
      cin >> x[i] >> y[i];
      x[i]--;y[i]--;
    }
    vector<vector<modint<mod> > > dp(n,vector<modint<mod> >(n,0));
    rep(i,n){
      rep(j,n){
        if(a[i]<a[j]){
          dp[i][j] = pow((modint<mod>)2,q);
        }
        //cerr << dp[i][j].value() << " ";
      }
      //cerr << endl;
    }
    modint<mod> half = 1;
    half /=2;
    rep(c,q){
      int a = x[c];
      int b = y[c];
      vector< modint<mod> > p(n),q(n);
      rep(i,n){
        p[i] = dp[i][a]*half + dp[i][b]*half;
      }
      rep(i,n){
        q[i] = dp[a][i]*half + dp[b][i]*half;
      } 
      rep(i,n){
        if(i!=a&&i!=b){
        dp[i][a] = p[i];
        dp[a][i] = q[i];
        dp[i][b] = p[i];
        dp[b][i] = q[i];
        }
      }
      dp[a][b] = (dp[a][b]*half+dp[b][a]*half);
      dp[b][a] = dp[a][b];
      // rep(i,n){
      //   rep(j,n){
      //     cerr << dp[i][j].value() << " ";
      //   }
      //   cerr << endl;
      // }
      // cerr << endl;
    }
    modint<mod> sm = 0;
    rep(i,n){
      rep(j,n){
        if(i<j)continue;
        sm += dp[i][j];
        //cerr << dp[i][j].value() << " ";
      }
      //cerr << endl;
    }
    cout << sm.value() << endl;
    return 0;

}

Measured memory_bytes: 72704