import sequtils,strutils,queues var W,H : int C = newSeq[string](0) cnt : int D = [[0, 1], [1, 0], [-1, 0], [0, -1]] (W, H) = stdin.readline.split.map(parseInt) for h in 1..H: C.add(stdin.readline) proc tansakuA(px, py : int)= var qu = initQueue[array[2, int]](1024) qu.add([py, px]) while qu.len > 0: var a = qu.pop C[a[0]][a[1]] = chr(cnt + ord('0')) for d in D: var (ny, nx) = (a[0] + d[1], a[1] + d[0]) if ny < 0 or ny >= H: continue if nx < 0 or ny >= W: continue if C[ny][nx] == '.': C[ny][nx] = chr(cnt + ord('0')) qu.add([ny, nx]) for i in 0..= H: continue if nx < 0 or nx >= W: continue if C[ny][nx] == '#': C[ny][nx] = char(cnt + 1 + ord('0')) elif C[ny][nx] == '0': echo cnt - 1 break tansaku cnt += 1