import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return list(map(float, input().split()))
def LS(): return input().split()
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def main():
h,w = LI()
a = [LI() for _ in range(h)]
r = 0
dy = [0,0,1,-1]
dx = [1,-1,0,0]
m = [[None]*w for _ in range(h)]
def f(y,x):
if m[y][x]:
return m[y][x]
r = 1
k = a[y][x]
for i in range(4):
ty,tx = y+dy[i], x+dx[i]
if 0 <= ty < h and 0 <= tx < w:
if a[ty][tx] >= k:
continue
r += f(ty,tx)
m[y][x] = r % mod
return m[y][x]
return sum(sum(f(i,j) for j in range(w)) % mod for i in range(h)) % mod
print(main())