import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import defaultdict H, W = map(int, readline().split()) A = [-1] * (W + 4) A += [-1] + [0] * (W + 2) + [-1] for _ in range(H): A += [-1, 0] + [1 * (x == ord('x')) for x in readline().rstrip()] + [0, -1] A += [-1] + [0] * (W + 2) + [-1] A += [-1] * (W + 4) H += 4 W += 4 N = H * W root = [0] * N for v in range(N): if A[v] or root[v]: continue stack = [v] root[v] = v while stack: v = stack.pop() for dx in (1, -1, W, -W): w = v + dx if A[w] or root[w]: continue root[w] = root[v] stack.append(w) component_size = defaultdict(int) for v in range(N): if A[v] != 1: continue nbd0 = [] nbdx = [] for dx in (1, -1, W - 1, W, W + 1, -W - 1, -W, -W + 1): w = v + dx if A[w]: nbdx.append(w) continue r = root[w] if not nbd0: nbd0.append(r) elif nbd0[0] != r and nbd0[-1] != r: nbd0.append(r) if len(nbd0) == 1: # 三角形 new_node = sum(pow(v, 10, 10 ** 9 + 7) for v in [v] + nbdx) nbd0.append(new_node) key = tuple(sorted(nbd0)) component_size[key] += 1 nodes = [] for (u, v) in component_size: nodes.append(u) nodes.append(v) nodes = sorted(set(nodes)) n_to_i = {n: i for i, n in enumerate(nodes)} N = len(nodes) if N == 0: print(0) exit() graph = [[] for _ in range(N)] for (u, v), x in component_size.items(): u = n_to_i[u] v = n_to_i[v] graph[u].append((v, x)) graph[v].append((u, x)) # あとは 木 dp root = 0 parent = [0] * N cost = [0] * N order = [] stack = [root] while stack: x = stack.pop() order.append(x) for y, c in graph[x]: if y == parent[x]: continue parent[y] = x cost[y] = c stack.append(y) dp0 = [0] * N dp1 = [0] * N for v in order[::-1][:-1]: p = parent[v] x = cost[v] dp0[p] += dp1[v] dp1[p] += max(dp0[v] + x, dp1[v]) print(dp1[0])