// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// contancer library
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v) os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "{";
    for (auto vv : v) os << vv << ",";
    return os << "}";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.first << "," << p.second << ")";
}

template <class K, class T>
ostream& operator<<(ostream& os, map<K, T> v) {
    os << "{";
    for (auto vv : v) os << vv << ",";
    return os << "}";
}

template <class T>
ostream& operator<<(ostream& os, queue<T> q) {
    os << "[";
    while (!q.empty()) {
        os << q.front() << ",";
        q.pop();
    }
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, priority_queue<T> q) {
    os << "{";
    while (!q.empty()) {
        os << q.top() << ",";
        q.pop();
    }
    return os << "}";
}

const ll MOD = 1000000007;
// const ll MOD = 998244353;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const ld PI = acos(-1);
// const ld EPS = 1e-10;
// mt19937 mt(ll(time(0)));

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...));
}

template <typename T>
inline T sq(T a) { return a * a; }

template <typename T>
inline T iceil(T n, T d) { return (n + d - 1) / d; }

template <typename T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

template <typename T, typename U>
T ipow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

template <typename T, typename U>
T mpow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * b % MOD;
        n >>= 1;
        b = b * b % MOD;
    }
    return ret;
}

const ll inv2 = mpow(2LL, MOD - 2);

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

    auto dp = Vec<ll>(N, N, 0LL);
    // 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] += dp[k][y];
            if (dp[k][x] & 1) {
                dp[k][x] = dp[k][x] * inv2 % MOD;
            } else {
                dp[k][x] /= 2;
            }
            dp[k][y] = dp[k][x];

            dp[x][k] += dp[y][k];
            if (dp[x][k] & 1) {
                dp[x][k] = dp[x][k] * inv2 % MOD;
            } else {
                dp[x][k] /= 2;
            }
            dp[y][k] = dp[x][k];
        }

        dp[x][y] += dp[y][x];
        if (dp[x][y] & 1) {
            dp[x][y] = dp[x][y] * inv2 % MOD;
        } else {
            dp[x][y] /= 2;
        }
        dp[y][x] = dp[x][y];
    }

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

    cout << ans % MOD * mpow(2LL, Q) % MOD << endl;
    return 0;
}


Measured memory_bytes: 70656