#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
template <ll mod> struct modint {
    ll val;
    inline ll extgcd(ll a, ll b, ll &x, ll &y) {
        if (a < b) {
            return extgcd(b, a, y, x);
        }
        if (b == 0) {
            x = 1, y = 0;
            return a;
        }
        ll d = extgcd(b, a % b, y, x);
        y -= a / b * x;
        return d;
    }
    inline ll minv(ll k) {
        ll x = 0, y = 0;
        extgcd(k, mod, x, y);
        if (x < 0) {
            x += mod;
        } else if (x == mod) {
            x = 0;
        }
        return x;
    }
    constexpr modint() : val(0) {}
    constexpr modint(ll x) { val = (x + mod) % mod; }
    modint inv() { return modint(minv(val)); }
    modint operator+(const modint &to) const { return modint(val + to.val); }
    modint operator-(const modint &to) const { return modint(val - to.val); }
    modint operator*(const modint &to) const { return modint(val * to.val); }
    modint operator/(const modint &to) const {
        return modint(val * minv(to.val));
    }
    template <class T> explicit operator T() { return T(val); }
    modint &operator++() { return *this = modint(val + 1); }
    modint &operator--() { return *this = modint(val - 1); }
    template <typename T> modint &operator+=(const T &to) {
        return *this = *this + to;
    }
    template <typename T> modint &operator-=(const T &to) {
        return *this = *this - to;
    }
    template <typename T> modint &operator*=(const T &to) {
        return *this = *this * to;
    }
    template <typename T> modint &operator/=(const T &to) {
        return *this = *this / to;
    }
    bool operator==(const modint &to) const { return val == to.val; }
    bool operator!=(const modint &to) const { return val != to.val; }
    bool operator>(const modint &to) const { return val > to.val; }
    bool operator>=(const modint &to) const { return val >= to.val; }
    bool operator<(const modint &to) const { return val < to.val; }
    bool operator<=(const modint &to) const { return val <= to.val; }
};
using mint = modint<MOD>;
mint dp[3010][3010];
int co[3010][3010];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i] > a[j]) {
                dp[i][j] = 1;
            } else {
                dp[i][j] = 0;
            }
            co[i][j] = -1;
        }
    }
    vector<mint> p(q + 1);
    p[0] = 1;
    for (int i = 1; i <= q; i++) {
        p[i] = p[i - 1] * 2LL;
    }
    for (ll i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        mint s =
            dp[x][y] * p[i - co[x][y] - 1] + dp[y][x] * p[i - co[y][x] - 1];
        dp[x][y] = s;
        dp[y][x] = s;
        co[x][y] = i;
        co[y][x] = i;
        for (int j = 0; j < n; j++) {
            if (j != x && j != y) {
                mint s1 = dp[j][x] * p[i - co[j][x] - 1] +
                          dp[j][y] * p[i - co[j][y] - 1],
                     s2 = dp[x][j] * p[i - co[x][j] - 1] +
                          dp[y][j] * p[i - co[y][j] - 1];
                dp[j][x] = s1;
                dp[x][j] = s2;
                dp[j][y] = s1;
                dp[y][j] = s2;
                co[x][j] = i;
                co[j][x] = i;
                co[y][j] = i;
                co[j][y] = i;
            }
        }
    }
    mint res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            res += dp[i][j] * p[q - co[i][j] - 1];
        }
    }
    cout << res.val << endl;
}


Measured memory_bytes: 106240