H, W = map(int, input().split()) world = [] for i in range(H): world.append(list(e for e in input())) # print(world) chash = dict() def how_much(h, w, state): global H, W, chash, world if h == H & w == W: return 1 if h > H or w > W: return 0 if world[h - 1][w - 1] == "#": return 0 if world[h - 1][w - 1] == "o": state += 1 if world[h - 1][w - 1] == "x": state -= 1 if state <= -1: return 0 # print(how_much(h + 1, w) + how_much(h, w + 1)) if (h, w) not in chash.keys(): chash["x:{},y:{},state:{}".format(h, w, state)] = how_much( h + 1, w, state ) + how_much(h, w + 1, state) return chash["x:{},y:{},state:{}".format(h, w, state)] # print(chash) print(how_much(1, 1, 0))