#include <iostream>
#include <vector>

using namespace std;

class ModInt {
    using ll = long long;

public:
    int value;
    static int MOD;

    ModInt(ll value = 0) {
        this->value = value % MOD;
        if (this->value < 0) this->value += MOD;
    }

    operator int() const noexcept { return this->value; }

    ModInt& operator=(const ModInt& x) {
        if (this != &x) { this->value = x.value; }
        return *this;
    }

    bool operator==(const ModInt& x) const { return this->value == x.value; }
    bool operator!=(const ModInt& x) const { return !(*this == x); }

    ModInt operator+() const { return value; }
    ModInt operator-() const { return MOD - value; }
    ModInt operator~() const { return (*this) ^ ModInt(MOD - 2); }

    ModInt operator++() { return *this += 1; }
    ModInt operator--() { return *this -= 1; }

    ModInt operator++(int) {
        ModInt before = *this;
        ++(*this);
        return before;
    }
    ModInt operator--(int) {
        ModInt before = *this;
        --(*this);
        return before;
    }

    ModInt operator+=(const ModInt& x) {
        int sum = this->value + x.value;
        return *this = (sum < MOD ? sum : sum - MOD);
    }
    ModInt operator-=(const ModInt& x) {
        int diff = this->value - x.value;
        return *this = (diff >= 0 ? diff : diff + MOD);
    }
    ModInt operator*=(const ModInt& x) { return *this = ll(this->value) * ll(x.value) % MOD; }
    ModInt operator/=(const ModInt& x) { return *this = (this->value % x.value == 0 ? ModInt(this->value / x.value) : *this * ~x); }

    ModInt operator+=(const int& x) {
        int sum = this->value + x;
        return *this = (sum < MOD ? sum : sum - MOD);
    }
    ModInt operator-=(const int& x) {
        int diff = this->value - x;
        return *this = (diff >= 0 ? diff : diff + MOD);
    }
    ModInt operator*=(const int& x) { return *this = ll(this->value) * ll(x) % MOD; }
    ModInt operator/=(const int& x) { return *this = (this->value % x == 0 ? ModInt(this->value / x) : *this * ~ModInt(x)); }

    template <class T>
    ModInt operator^=(const T& x) {
        int n = int(x);
        if (n == 0) return ModInt(1);
        if (n & 1) {
            return (*this) = ((*this) ^ ModInt(n - 1)) * (*this);
        } else {
            return (*this) = ((*this) * (*this)) ^ ModInt(n / 2);
        }
    }

    template <class T>
    ModInt operator+(const T& b) const { return ModInt(*this) += b; }
    template <class T>
    ModInt operator-(const T& b) const { return ModInt(*this) -= b; }
    template <class T>
    ModInt operator*(const T& b) const { return ModInt(*this) *= b; }
    template <class T>
    ModInt operator/(const T& b) const { return ModInt(*this) /= b; }
    template <class T>
    ModInt operator^(const T& b) const { return ModInt(*this) ^= b; }
};

int ModInt::MOD = 1000000007;

ostream& operator<<(ostream& os, const ModInt& x) { return os << x.value; }
istream& operator>>(istream& is, ModInt& x) { return is >> x.value; }

template <class T>
vector<T> Vec(size_t l, T v) { return vector<T>(l, v); }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}

const ModInt inv2 = ~ModInt(2);

inline ModInt div2(ModInt n) {
    return (n.value & 1 ? n * inv2 : ModInt(n.value / 2));
}

int main() {
    int N, Q;
    cin >> N >> Q;
    auto A = Vec<int>(N, 0);
    for (int& a : A) cin >> a;

    auto dp = Vec<ModInt>(N, N, ModInt(0));
    // i番目がj番目より大きい確率

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            dp[i][j] = (A[i] > A[j] ? 1 : 0);
        }
    }

    for (int q = 0; q < Q; ++q) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        for (int k = 0; k < N; ++k) {
            if (k == x || k == y) continue;
            dp[k][x] = div2(dp[k][x] + dp[k][y]);
            dp[k][y] = dp[k][x];

            dp[x][k] = div2(dp[x][k] + dp[y][k]);
            dp[y][k] = dp[x][k];
        }

        dp[x][y] = div2(dp[x][y] + dp[y][x]);
        dp[y][x] = dp[x][y];
    }

    ModInt ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            ans += dp[i][j];
        }
    }

    cout << ans * (ModInt(2) ^ Q) << endl;
    return 0;
}


Measured memory_bytes: 37632