#include<bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end());
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
template<typename T1, typename T2> inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> inline bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

template<int MOD = 1000000007>
struct ModInt {
    int val;
    ModInt(long long val_ = 0) : val(val_ >= 0 ? val_ % MOD : (MOD - (-val_) % MOD) % MOD) {}
    bool operator==(const ModInt &rhs) const { return val == rhs.val; }
    bool operator!=(const ModInt &rhs) const { return val != rhs.val; }
    ModInt &operator+=(const ModInt &rhs) {
        if ((val += rhs.val) >= MOD) { val -= MOD; }
        return *this;
    }
    ModInt &operator-=(const ModInt &rhs) {
        if ((val += MOD - rhs.val) >= MOD) { val -= MOD; }
        return *this;
    }
    ModInt &operator*=(const ModInt &rhs) {
        val = (int) ((long long) val * rhs.val % MOD);
        return *this;
    }
    ModInt &operator/=(const ModInt &rhs) { return *this *= rhs.inv(); }
    ModInt operator+() const { return *this; }
    ModInt operator-() const { return ModInt(-val); }
    ModInt operator++() { return *this += 1; }
    ModInt operator--() { return *this -= 1; }
    ModInt operator++(signed) {
        const ModInt ret(*this);
        ++*this;
        return ret;
    }
    ModInt operator--(signed) {
        const ModInt ret(*this);
        --*this;
        return ret;
    }
    ModInt operator+(const ModInt &rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(const ModInt &rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(const ModInt &rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(const ModInt &rhs) const { return ModInt(*this) /= rhs; }
    ModInt inv() const {
        int a = val, b = MOD, u = 1, v = 0;
        while (b > 0) {
            int t = a / b;
            std::swap(a -= t * b, b);
            std::swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(long long n) const {
        ModInt ret = 1, mul = *this;
        if (n < 0) { n = -n, mul = mul.inv(); }
        while (n > 0) {
            if (n & 1) { ret *= mul; }
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend std::istream &operator>>(std::istream &is, ModInt &rhs) {
        long long v;
        is >> v;
        rhs = v;
        return is;
    }
    friend std::ostream &operator<<(std::ostream &os, const ModInt &rhs) { return os << rhs.val; }
    struct Combination {
        std::vector<ModInt> fact, finv, inv;
        Combination(int n) : fact(n + 1), finv(n + 1), inv(n + 1) {
            fact[0] = fact[1] = 1;
            finv[0] = finv[1] = 1;
            inv[1] = 1;
            for (int i = 2; i <= n; i++) {
                fact[i] = fact[i - 1] * i;
                inv[i] = -inv[MOD % i] * (MOD / i);
                finv[i] = finv[i - 1] * inv[i];
            }
        }
        ModInt P(int n, int r) const { return r < 0 || n < r ? 0 : fact[n] * finv[n - r]; }
        ModInt C(int n, int r) const { return r < 0 || n < r ? 0 : fact[n] * finv[r] * finv[n - r]; }
        ModInt H(int n, int r) const { return C(n + r - 1, r); }
    };
};

int N, Q;
int A[3300], X[3300], Y[3300];
using Mint=ModInt<>;
Mint dp[3300][3300];
Mint pow2[3300];
int last[3300][3300];
signed main() {
    cin >> N >> Q;
    rep(i, N) { cin >> A[i]; }
    rep(i, Q) { cin >> X[i] >> Y[i], X[i]--, Y[i]--; }
    rep(i, N)rep(j, N) { if (A[i] < A[j]) { dp[i][j] = 1; }}
    pow2[0] = 1;
    reps(i, Q) { pow2[i] = pow2[i - 1] * 2; }
    rep(i, Q) {
        rep(j, N) {
            dp[X[i]][j] *= pow2[max(0LL, i - last[X[i]][j])];
            last[X[i]][j] = i + 1;
            dp[Y[i]][j] *= pow2[max(0LL, i - last[Y[i]][j])];
            last[Y[i]][j] = i + 1;
        }
        rep(j, N) {
            dp[j][X[i]] *= pow2[max(0LL, i - last[j][X[i]])];
            last[j][X[i]] = i + 1;
            dp[j][Y[i]] *= pow2[max(0LL, i - last[j][Y[i]])];
            last[j][Y[i]] = i + 1;
        }
        rep(j, N) { dp[X[i]][j] = dp[Y[i]][j] = dp[X[i]][j] + dp[Y[i]][j]; }
        rep(j, N) { dp[j][X[i]] = dp[j][Y[i]] = dp[j][X[i]] + dp[j][Y[i]]; }
        dp[X[i]][X[i]] = dp[Y[i]][Y[i]] = 0;
    }
    Mint ans = 0;
    rep(i, N)rep(j, i) { ans += dp[i][j] * pow2[Q - last[i][j]]; }
    cout << ans << endl;
}

Measured memory_bytes: 164480