map_height,map_width=map(int,input().split())
d={'.':0,'#':-1}
map_data= [list(map(lambda x: d[x],list(input()))) for _ in range(map_height)]

import itertools
Z= map_width*map_height

#m = np.ones((map_width*map_height,map_width*map_height))*float("inf")
m = [[401 for _ in range(Z)] for _ in range(Z)]
for i,j in itertools.product(range(map_height),range(map_width)):
    if map_data[i][j] == 0:
        for i_n, j_n in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]:
            if 0 <= i_n < map_height and 0 <= j_n < map_width:
                if map_data[i_n][j_n] == 0:
                    m[map_width*i+j][map_width*i_n+j_n] = 1
for k in range(Z):
    for i in range(Z):
        for j in range(Z):
            temp = min(m[i][j],m[i][k] + m[k][j])
            m[i][j] = temp
                
ans = 0
for i in range(Z):
    for j in range(Z):
        temp = m[i][j]
        if temp != 401:
            if ans < m[i][j]:
                ans = m[i][j]
print(ans)