import numpy as np
from scipy.ndimage.filters import minimum_filter, maximum_filter

h,w=map(int,input().split())
maze=[]
for i in range(h):
  maze.append(input())    

cost = np.zeros((h,w),dtype = int) + 999
done = np.zeros((h,w),dtype = bool)
barrier = np.zeros((h,w),dtype = bool)

g=np.array([[0,1,0],
            [1,1,1],
            [0,1,0]])

for i in range(h):
    maze[i]=list(maze[i])
    for j in range(w):
        if maze[i][j] == '#':
           barrier[i][j]= True

n_cost_max=0
for ystart in range(h):
    for xstart in range(w):
        if barrier[ystart,xstart]:
            break
        else:
            cost.fill(999)
            done.fill(False)
            cost[ystart,xstart]=0
            done[ystart,xstart]=True
            for i in range(999):
                n_done=(np.count_nonzero(done+barrier))
                if n_done==done.size:
                    break
                else:
                    done_next = maximum_filter(done,footprint=g)*~done
                    cost_next = minimum_filter(cost,footprint=g)
                    cost_next[done_next] +=1
                    cost[done_next]=cost_next[done_next]
                    cost[barrier]=999
                    done[done_next]=done_next[done_next]
                    done[barrier]=False
            n_cost=np.max(cost*~barrier)
            if n_cost > n_cost_max:
                n_cost_max = n_cost
print(n_cost_max)

