ways = [(1, 0), (0, 1)] H, W = map(int, input().split()) A = [list(input()) for _ in range(H)] def is_object(i, j): return (i < 0 or H <= i) or (j < 0 or W <= j) or A[i][j] == '#' ans = 0 def dfs(now_i, now_j, cost): global ans for y, x in ways: next_i, next_j = now_i + y, now_j + x if is_object(next_i, next_j): continue next_cost = cost + (1 if A[next_i][next_j] == 'o' else -1) if next_cost < 0: continue if (next_i, next_j) == (H-1, W-1): ans += 1 else: dfs(next_i, next_j, next_cost) dfs(0, 0, 1) print(ans)