#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>

template <uint32_t Modulus>
class modular {
public:
  using value_type = uint32_t;
  using max_type = uint64_t;

  static constexpr value_type mod = Modulus;
  static constexpr value_type get_mod() { return mod; }
  static_assert(mod >= 2, "invalid mod :: smaller than 2");
  static_assert(mod < (value_type(1) << 31), "invalid mod :: over 2^31");

  template <class T>
  static constexpr value_type normalize(T value_) {
    if (value_ < 0) {
      value_ = -value_;
      value_ %= mod;
      if (value_ == 0) return 0;
      return mod - value_;
    }
    return value_ % mod;
  }

private:
  value_type value;

public:
  constexpr modular(): value(0) { }
  template <class T>
  explicit constexpr modular(T value_): value(normalize(value_)) { }
  template <class T>
  explicit constexpr operator T() { return static_cast<T>(value); }

  constexpr value_type get() const { return value; }
  constexpr modular operator - () const { return modular(mod - value); }
  constexpr modular operator ~ () const { return inverse(); }

  constexpr value_type &extract() { return value; }
  constexpr modular inverse() const { return power(mod - 2); }
  constexpr modular power(max_type exp) const {
    modular res(1), mult(*this);
    while (exp > 0) {
      if (exp & 1) res *= mult;
      mult *= mult;
      exp >>= 1;
    }
    return res;
  }

  constexpr modular operator + (const modular &rhs) const { return modular(*this) += rhs; }
  constexpr modular& operator += (const modular &rhs) { 
    if ((value += rhs.value) >= mod) value -= mod; 
    return *this; 
  }

  constexpr modular operator - (const modular &rhs) const { return modular(*this) -= rhs; }
  constexpr modular& operator -= (const modular &rhs) { 
    if ((value += mod - rhs.value) >= mod) value -= mod; 
    return *this; 
  }

  constexpr modular operator * (const modular &rhs) const { return modular(*this) *= rhs; }
  constexpr modular& operator *= (const modular &rhs) { 
    value = (max_type) value * rhs.value % mod;
    return *this;
  }

  constexpr modular operator / (const modular &rhs) const { return modular(*this) /= rhs; }
  constexpr modular& operator /= (const modular &rhs) { return (*this) *= rhs.inverse(); }

  constexpr bool zero() const { return value == 0; }
  constexpr bool operator == (const modular &rhs) const { return value == rhs.value; }
  constexpr bool operator != (const modular &rhs) const { return value != rhs.value; }
  friend std::ostream& operator << (std::ostream &stream, const modular &rhs) {
    return stream << rhs.value;
  }

};

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
using m32 = modular<1000000007>;

constexpr auto pow2 = [] {
  std::array<m32, 3010> res;
  res[0] = m32(1);
  for (size_t i = 1; i < 3010; ++i) {
    res[i] = res[i - 1] * m32(2);
  }
  return res;
}();

class propagation_array {
private:
  size_t count;
  std::vector<std::vector<m32>> data;
  std::vector<std::vector<size_t>> done;

public:
  propagation_array(size_t h, size_t w): 
    count(0), 
    data(h, std::vector<m32>(w)), 
    done(h, std::vector<size_t>(w)) 
  { }

  void multiply() {
    ++count;
  }

  void reduce(size_t i, size_t j) {
    done[i][j] = std::min(done[i][j] + 1, count);
  }

  m32& access(size_t i, size_t j) {
    data[i][j] *= pow2[count - done[i][j]];
    done[i][j] = count;
    return data[i][j];
  }

};

int main() {
  size_t N, Q;
  std::cin >> N >> Q;
  std::vector<i32> A(N);
  for (auto &x: A) {
    std::cin >> x;
  }
  propagation_array invert(N, N);
  for (size_t i = 0; i < N; ++i) {
    for (size_t j = 0; j < N; ++j) {
      if (A[i] < A[j]) {
        invert.access(i, j) = m32(1);
      }
    }
  }
  while (Q--) {
    size_t x, y;
    std::cin >> x >> y;
    --x; --y;
    if (x > y) {
      std::swap(x, y);
    }
    invert.multiply();
    for (size_t k = 0; k < N; ++k) {
      if (k != x && k != y) {
        invert.reduce(k, x);
        invert.reduce(k, y);
        invert.reduce(x, k);
        invert.reduce(y, k);
        invert.access(k, x) = invert.access(k, y) = invert.access(k, x) + invert.access(k, y);
        invert.access(x, k) = invert.access(y, k) = invert.access(x, k) + invert.access(y, k);
      }
    }
    invert.reduce(x, x);
    invert.reduce(x, y);
    invert.reduce(y, x);
    invert.reduce(y, y);
    invert.access(x, y) = invert.access(y, x) = invert.access(x, y) + invert.access(y, x);
    invert.access(x, x) = invert.access(y, y) = invert.access(x, x) + invert.access(y, y);
  }
  m32 ans;
  for (size_t i = 0; i < N; ++i) {
    for (size_t j = 0; j < i; ++j) {
      ans += invert.access(i, j);
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 109112