from collections import deque
H,W = map(int,input().split())
S = list(list(input())for _ in range(H))
ans = 0
for sh in range(H):
    for sw in range(W):
        queue = deque([[sh,sw]])
        cost = [[10000]*W for i in range(H)]
        cost[sh][sw] = 0
        while queue:
            h,w = queue.popleft()
            for nh,nw in [[h-1,w],[h,w-1],[h+1,w],[h,w+1]]:
                if not (0 <= nh < H and 0 <= nw < W):
                    continue
                if S[nh][nw] == '.' and cost[nh][nw] > cost[h][w]+1:
                    cost[nh][nw] = cost[h][w]+1
                    queue.append([nh,nw])
                    ans = max(ans,cost[nh][nw])
print(ans)