import sys



n, q = list(map(int, input().split()))

MOD = 10 ** 9 + 7

INV2 = (MOD + 1) // 2

lines = sys.stdin.readlines()

aaa = list(map(int, lines[:n]))

mat = [[0] * n for _ in [0] * n]

for i in range(n):

    for j in range(n):

        mat[i][j] = int(aaa[i] < aaa[j])

# print(*mat, sep='\n')

for line in lines[n:]:

    x, y = list(map(int, line.split()))

    x -= 1

    y -= 1

    mat[x][y] = mat[y][x] = (mat[x][y] + mat[y][x]) * INV2 % MOD

    for i in range(n):

        if i == x or i == y:

            continue

        mat[x][i] = mat[y][i] = (mat[x][i] + mat[y][i]) * INV2 % MOD

        mat[i][x] = mat[i][y] = (mat[i][x] + mat[i][y]) * INV2 % MOD

    # print(x, y)

    # print(*mat, sep='\n')



ans = sum(sum(row[:i]) for i, row in enumerate(mat)) % MOD

ans = (ans << q) % MOD

print(ans)

import sys

import numpy as np



n, q = list(map(int, input().split()))

MOD = 10 ** 9 + 7

INV2 = (MOD + 1) // 2

lines = sys.stdin.readlines()

aaa = np.fromiter(list(map(int, lines[:n])), dtype=np.int)

mat = (aaa.reshape(1, -1) < aaa.reshape(-1, 1)).astype(np.int64)

# print(mat)

for line in lines[n:]:

    x, y = list(map(int, line.split()))

    x -= 1

    y -= 1

    tmp = (mat[x, y] + mat[y, x]) * INV2 % MOD

    mat[x] = mat[y] = (mat[x] + mat[y]) * INV2 % MOD

    mat[:, x] = mat[:, y] = (mat[:, x] + mat[:, y]) * INV2 % MOD

    mat[x, x] = mat[y, y] = 0

    mat[x, y] = mat[y, x] = tmp



ans = int(np.triu(mat).sum() % MOD)

ans = (ans << q) % MOD

print(ans)

import sys

n, q = list(map(int, input().split()))
MOD = 10**9 + 7
INV2 = (MOD + 1) // 2
lines = sys.stdin.readlines()
aaa = list(map(int, lines[:n]))
mat = [[0] * n for _ in [0] * n]
for i in range(n):
    for j in range(n):
        mat[i][j] = int(aaa[i] < aaa[j])
# print(*mat, sep='\n')
for line in lines[n:]:
    x, y = list(map(int, line.split()))
    x -= 1
    y -= 1
    mat[x][y] = mat[y][x] = (mat[x][y] + mat[y][x]) * INV2 % MOD
    for i in range(n):
        if i == x or i == y:
            continue
        mat[x][i] = mat[y][i] = (mat[x][i] + mat[y][i]) * INV2 % MOD
        mat[i][x] = mat[i][y] = (mat[i][x] + mat[i][y]) * INV2 % MOD
    # print(x, y)
    # print(*mat, sep='\n')
ans = sum(sum(row[:i]) for i, row in enumerate(mat)) % MOD
ans = (ans << q) % MOD
print(ans)

import sys
import numpy as np

n, q = list(map(int, input().split()))
MOD = 10**9 + 7
INV2 = (MOD + 1) // 2
lines = sys.stdin.readlines()
aaa = np.fromiter(list(map(int, lines[:n])), dtype=np.int)
mat = (aaa.reshape(1, -1) < aaa.reshape(-1, 1)).astype(np.int64)
# print(mat)
for line in lines[n:]:
    x, y = list(map(int, line.split()))
    x -= 1
    y -= 1
    tmp = (mat[x, y] + mat[y, x]) * INV2 % MOD
    mat[x] = mat[y] = (mat[x] + mat[y]) * INV2 % MOD
    mat[:, x] = mat[:, y] = (mat[:, x] + mat[:, y]) * INV2 % MOD
    mat[x, x] = mat[y, y] = 0
    mat[x, y] = mat[y, x] = tmp
ans = int(np.triu(mat).sum() % MOD)
ans = (ans << q) % MOD
print(ans)

+import numpy as np -aaa = list(map(int, lines[:n])) -mat = [[0] * n for _ in [0] * n] -for i in range(n): -    for j in range(n): -        mat[i][j] = int(aaa[i] < aaa[j]) -# print(*mat, sep='\n') +aaa = np.fromiter(list(map(int, lines[:n])), dtype=np.int) +mat = (aaa.reshape(1, -1) < aaa.reshape(-1, 1)).astype(np.int64) +# print(mat) -    mat[x][y] = mat[y][x] = (mat[x][y] + mat[y][x]) * INV2 % MOD -    for i in range(n): -        if i == x or i == y: -            continue -        mat[x][i] = mat[y][i] = (mat[x][i] + mat[y][i]) * INV2 % MOD -        mat[i][x] = mat[i][y] = (mat[i][x] + mat[i][y]) * INV2 % MOD -    # print(x, y) -    # print(*mat, sep='\n') -ans = sum(sum(row[:i]) for i, row in enumerate(mat)) % MOD +    tmp = (mat[x, y] + mat[y, x]) * INV2 % MOD +    mat[x] = mat[y] = (mat[x] + mat[y]) * INV2 % MOD +    mat[:, x] = mat[:, y] = (mat[:, x] + mat[:, y]) * INV2 % MOD +    mat[x, x] = mat[y, y] = 0 +    mat[x, y] = mat[y, x] = tmp +ans = int(np.triu(mat).sum() % MOD)