import itertools
n, m = map(int,input().split())
a = [int(input()) for i in range(m)] 

narray = [0]*(n+1)
back = 0
tmp = 1
cnt = 1

for i in a:
    for j in range(m-1):
        if a[j] == a[j+1]:
            print(0)
            break
    else:
        if cnt == 1:
            size = len(narray[0:i])
            tmp = len(list(itertools.permutations(range(size-1))))
            size = len(narray[i:+1])
            tmp = len(list(itertools.permutations(range(size-1))))*tmp
            cnt = cnt -1
        else:
            size = len(narray[i+1:])
            tmp = len(list(itertools.permutations(range(size-1))))*tmp
        continue
    break

ans = tmp%1000000007
print(int(ans))