import sys input = sys.stdin.readline # dinic法 from collections import defaultdict,deque N,M=map(int,input().split()) MAP=[input().strip() for i in range(N)] V=N*M+2 EDGE=[defaultdict(int) for i in range(N*M+2)] for i in range(N): for j in range(M): if MAP[i][j]=="w": for z,w in [(i+1,j),(i-1,j),(i,j+1),(i,j-1)]: if 0<=z