from collections import deque
import numpy as np


H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype=int)

for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
S= np.zeros_like(T, dtype=int)
d=0
c=deque()

for i in range(H):
    for j in range(W):

        if T[i][j] ==1:continue

        c+=[i,j]
        S[i][j]=1
        
        while True:
            
                #print(c)
                try:
                    m = c.popleft()
                    n = c.popleft()
                except IndexError:
                    break
                if m != H-1:
                    if T[m+1][n]==0 and S[m+1][n]==0:
                        c+=[m+1,n]
                        S[m+1][n] = S[m][n]+1
                if m != 0:
                    if T[m-1][n]==0 and S[m-1][n]==0:
                        c+=[m-1,n]
                        S[m-1][n] = S[m][n]+1
                if n != W-1:
                    if T[m][n+1]==0 and S[m][n+1]==0:
                        c+=[m,n+1]
                        S[m][n+1] = S[m][n]+1
                if n != 0:
                    if T[m][n-1]==0 and S[m][n-1]==0:
                        c+=[m,n-1]
                        S[m][n-1] = S[m][n]+1

        print(S)
        d = max(d,np.max(S))
        S = np.zeros_like(T, dtype=int)

print(d-1)
