import sys
from collections import deque

H,W=map(int,input().split())
maze=[input() for i in range(H)]

def bfs(sy,sx):
    queue = deque([[sy,sx]])
    log = [[0 for i in range(W)] for j in range(H)]
    while queue:
        p = queue.popleft()

        for i,j in [1,0],[-1,0],[0,1],[0,-1]:
            next_p = [p[0]+i,p[1]+j]
            
            if 0 <= next_p[0] < H and 0 <= next_p[1] < W:
                if maze[next_p[0]][next_p[1]] == '.'\
                    and log[next_p[0]][next_p[1]] == 0:
                    log[next_p[0]][next_p[1]] = log[p[0]][p[1]] + 1
                    queue.append([next_p[0],next_p[1]])
    
    return log

for i in range(H):
    for j in range(W):
        if maze[i][j] == '.':
            tmp_i = i
            tmp_j = j
            break

tmplog = bfs(tmp_i,tmp_j)
max_v = 0

for i in range(H):
    for j in range(W):
        if tmplog[i][j] > max_v:
            max_v = tmplog[i][j]
            tmp_i = i
            tmp_j = j

tmplog = bfs(tmp_i,tmp_j)
max_v = 0

for i in range(H):
    for j in range(W):
        if tmplog[i][j] > max_v:
            max_v = tmplog[i][j]
            s_y = i
            s_x = j

finlog = bfs(s_y,s_x)

for i in range(H):
    for j in range(W):
        if finlog[i][j] > max_v:
            max_v = finlog[i][j]

print(max_v)