import sys input=lambda: sys.stdin.readline().rstrip() w,h=map(int,input().split()) C=[input() for _ in range(h)] n=w*h edge=[[] for i in range(n)] import heapq def dijkstra_heap(s): d=[float("inf")]*n used=[True]*n d[s]=0 used[s]=False edgelist=[] for e in edge[s]: heapq.heappush(edgelist,e) while edgelist: minedge=heapq.heappop(edgelist) minedge_cost=minedge//(10**6) minedge_v=minedge%(10**6) if not used[minedge_v]: continue d[minedge_v] = minedge_cost used[minedge_v] = False for e in edge[minedge_v]: e_cost=e//(10**6) e_v=e%(10**6) if used[e_v]: heapq.heappush(edgelist,e+minedge_cost*10**6) return d S=[] for i in range(h): for j in range(w): if C[i][j]=="." and not S: S.append(i*w+j) if i!=0: if C[i-1][j]=="#": edge[i*w+j].append(10**6+(i-1)*w+j) else: edge[i*w+j].append((i-1)*w+j) if j!=w-1: if C[i][j+1]=="#": edge[i*w+j].append(10**6+i*w+j+1) else: edge[i*w+j].append(i*w+j+1) if i!=h-1: if C[i+1][j]=="#": edge[i*w+j].append(10**6+(i+1)*w+j) else: edge[i*w+j].append((i+1)*w+j) if j!=0: if C[i][j-1]=="#": edge[i*w+j].append(10**6+i*w+j-1) else: edge[i*w+j].append(i*w+j-1) D=dijkstra_heap(S[0]) ans=0 for i in range(h): for j in range(w): if C[i][j]==".": ans=max(ans,D[i*w+j]) print(ans)