#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


template<class Int> constexpr bool is_prime(Int n) {
  if (n < 2 or n > 2 and ~n & 1) return false;
  for (Int i = 3; i * i <= n; i += 2) if (n % i == 0) return false;
  return true;
}
template<uint P> struct ModInt {
  static_assert(is_prime(P), "template argument must be a prime number");
  using M = ModInt;
  uint v;
  ModInt() : v(0) {}
  template<class Int> ModInt(Int x) : v(x >= 0 ? x % P : -x % P ? P - -x % P : 0) {}
  ModInt(uint v, int _) : v(v) {} // 直接値を初期化
  static constexpr uint p() { return P; }
  M operator++(int) { M t = *this; if (++v == P) v = 0; return t; }
  M operator--(int) { M t = *this; v = (v ? v : P) - 1; return t; }
  M& operator++() { if (++v == P) v = 0; return *this; }
  M& operator--() { v = (v ? v : P) - 1; return *this; }
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !static_cast<bool>(*this); }
  M operator*(M rhs) const { return M(*this) *= rhs; }
  M operator/(M rhs) const { return M(*this) /= rhs; }
  M operator+(M rhs) const { return M(*this) += rhs; }
  M operator-(M rhs) const { return M(*this) -= rhs; }
  bool operator==(M rhs) { return v == rhs.v; }
  bool operator!=(M rhs) { return !(*this == rhs); }
  M& operator*=(M rhs) { v = (ulint) v * rhs.v % P; return *this; }
  M& operator/=(M rhs) { return *this *= rhs.inv(); }
  M& operator+=(M rhs) { v = rhs.v < P - v ? v + rhs.v : v - (P - rhs.v); return *this; }
  M& operator-=(M rhs) { v = rhs.v <= v ? v - rhs.v : v + (P - rhs.v); return *this; }
  M inv() const {
    assert(v);
    #ifdef __linux__ // ACとCFで動作を変えるための仮の対処
      return pow(P - 2);
    #else
      int a = v, b = P, x = 1, u = 0;
      while (b) {
        int q = a / b;
        swap(a -= q * b, b);
        swap(x -= q * u, u);
      }
      return x;
    #endif
  }
  template<class Int> M pow(Int n) const {
    n = n >= 0 ? n % (P - 1) : P - 1 - -n % (P - 1);
    M res = 1;
    for (M a = *this; n > 0; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
  template<class Int> friend M operator*(Int lhs, M rhs) { return M(lhs) *= rhs; }
  template<class Int> friend M operator/(Int lhs, M rhs) { return M(lhs) /= rhs; }
  template<class Int> friend M operator+(Int lhs, M rhs) { return M(lhs) += rhs; }
  template<class Int> friend M operator-(Int lhs, M rhs) { return M(lhs) -= rhs; }
  friend ostream& operator<<(ostream& os, M rhs) { return os << rhs.v; }
  friend istream& operator>>(istream& is, M& rhs) { lint x; is >> x; rhs = x; return is; }
  template<class Int> friend bool operator==(Int lhs, M rhs) { return M(lhs) == rhs; }
  template<class Int> friend bool operator!=(Int lhs, M rhs) { return !(lhs == rhs); }
};

using Mint = ModInt<static_cast<uint>(1e9 + 7)>;

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, q; cin >> n >> q;
  V<> a(n); for (int i = 0; i < n; ++i) cin >> a[i];
  V<> x(q), y(q);
  for (int i = 0; i < q; ++i) {
    cin >> x[i] >> y[i], --x[i], --y[i];
    if (x[i] > y[i]) swap(x[i], y[i]);
  }
  VV<Mint> dp0, dp1;
  assign(dp0, n, n, 0);
  assign(dp1, n, n, 0);
  Mint i2 = Mint(2).inv();
  for (int i = q - 1; i >= 0; --i) {
    dp0[x[i]][y[i]] = i2 * dp1[x[i]][y[i]] + i2 * (1 - dp1[x[i]][y[i]]);
    for (int l = 0; l < x[i]; ++l) {
      dp0[l][x[i]] = i2 * dp1[l][x[i]] + i2 * dp1[l][y[i]];
      dp0[l][y[i]] = i2 * dp1[l][y[i]] + i2 * dp1[l][x[i]];
    }
    for (int m = x[i] + 1; m < y[i]; ++m) {
      dp0[x[i]][m] = i2 * dp1[x[i]][m] + i2 * (1 - dp1[m][y[i]]);
      dp0[m][y[i]] = i2 * dp1[m][y[i]] + i2 * (1 - dp1[x[i]][m]);
    }
    for (int r = y[i] + 1; r < n; ++r) {
      dp0[x[i]][r] = i2 * dp1[x[i]][r] + i2 * dp1[y[i]][r];
      dp0[y[i]][r] = i2 * dp1[y[i]][r] + i2 * dp1[x[i]][r];
    }
    dp1[x[i]][y[i]] = dp0[x[i]][y[i]];
    for (int l = 0; l < x[i]; ++l) {
      dp1[l][x[i]] = dp0[l][x[i]];
      dp1[l][y[i]] = dp0[l][y[i]];
    }
    for (int m = x[i] + 1; m < y[i]; ++m) {
      dp1[x[i]][m] = dp0[x[i]][m];
      dp1[m][y[i]] = dp0[m][y[i]];
    }
    for (int r = y[i] + 1; r < n; ++r) {
      dp1[x[i]][r] = dp0[x[i]][r];
      dp1[y[i]][r] = dp0[y[i]][r];
    }
  }
  Mint res = 0;
  for (int l = 0; l < n; ++l) for (int r = l + 1; r < n; ++r) {
    if (a[l] < a[r]) {
      res += dp0[l][r];
    }
    if (a[l] > a[r]) {
      res += 1 - dp0[l][r];
    }
  }
  res *= Mint(2).pow(q);
  cout << res << '\n';
}

Measured memory_bytes: 72832