h, w = map(int, input().split()) a = [list(input()) for _ in range(h)] from collections import deque dij = [(1, 0), (0, 1)] q = deque() visited = [[0]*w for _ in range(h)] dist = [[1<<60]*w for _ in range(h)] q.append((1, 0, 0)) visited[0][0] = 1 dist[0][0] = 0 while q: t, i, j = q.popleft() for di, dj in dij: ni = di+i nj = dj+j nt = t if not (0<=ni dist[i][j]+1: q.append((nt, ni, nj)) dist[ni][nj] = min(dist[ni][nj], dist[i][j]+1) visited[ni][nj] += visited[i][j] print(visited[h-1][w-1])