import sys
h, w = map(int, sys.stdin.readline().split())
A = [sys.stdin.readline().rstrip() for i in range(h)]
A.insert(0, '#'*w)
A.append('#'*w)
for i in range(h+2):
    A[i] = '#' + A[i] + '#'

dp = [[0 for j in range(w+2)] for i in range(h+2)]

i,j=1, 1
before = [0, 0]
while True:
    if A[i][j]=='.' and before!=[i-1, j]:
        if A[i-1][j]=='.':
            dp[i-1][j] = dp[i][j]+1
            i, j = i-1, j
        if A[i+1][j]=='.' and before!=[i+1, j]:
            dp[i+1][j] = dp[i][j]+1
            i, j = i+1, j
        if A[i][j-1]=='.' and before!=[i, j-1]:
            dp[i][j-1] = dp[i][j]+1
            i, j = i, j-1
        if A[i][j+1]=='.' and before!=[i, j+1]:
            dp[i][j+1] = dp[i][j]+1
            i, j = i, j+1
        before = [i, j]
        if [i,j]== [2,1]:
            break
for h in dp:
    print(h)