from collections import deque
import numpy as np
H,W = map(int,input().split())
s = [list(input()) for _ in range(H)]

state = [[-1]*W for _ in range(H)]
start_list = []
for i in range(H):
    for j in range(W):
        if s[i][j] == '.':
            start_list.append((i,j))
            state[i][j] = 0

def dfs(black_cells,state):
    d = 0
    dist = [[0]*W for _ in range(H)]
    while black_cells:
        h, w =  black_cells.popleft()
        #print(h,w)
        d = dist[h][w]
        for dy, dx in ((1,0), (0,1), (-1,0), (0,-1)):
            new_h = h+dy
            new_w = w+dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if state[new_h][new_w] == 0 and dist[new_h][new_w] == 0:
                dist[new_h][new_w] = d+1
                black_cells.append((new_h, new_w))
    return np.array(dist).max()

ans = 0
for start in start_list:
    black_cells = deque()
    black_cells.append((start))
    ans = max(ans, dfs(black_cells,state))
print(ans)