
def get_neighbors(S, i):
    n = []
    if S[i]:
        if i >= W: #First row
            if S[i-W]:
                n += [i-W]
        if i < (H-1)*W:
            if S[i+W]:
                n += [i+W]
        if i % W > 0:
            if S[i-1]:
                n += [i-1]
        if i % W < W-1:
            if S[i+1]:
                n += [i+1]
    return n

import numpy as np
H, W = map(int, raw_input().split())
S = np.empty(H*W, bool)

for i in xrange(H):
    S[i*W:(i+1)*W] = map(lambda x: x==".", raw_input())
    
NR = sum(S) # Number of road cube
NE = [] # The neighbors
for i in xrange(H*W):
    NE += [get_neighbors(S, i)]

M = np.zeros([H*W, H*W], int)
# init
for i,n in enumerate(NE):
    for j in n:
        M[i,j] = 1
        
# find road
I = np.sum(M != 0)
Count = 2

while I < NR *NR:
    a = []
    for i,n in enumerate(NE):
        for j in n:
            a = np.logical_and(M[i] == 0, M[j] == Count-1)
            M[i][a] = Count
    I = np.sum(M != 0)
    Count += 1

print(Count - 1)
    
        