def main():
    from collections import deque
    H, W = list(map(int, input().split()))
    maps =[list(input()) for _ in range(H)]
    mv = {(1, 0), (-1, 0), (0, 1), (0, -1)}

    ans = 0
    for i in range(H):
        for j in range(W):
            if maps[i][j] == '#':
                continue
            stk = deque([[i,j,0]])
            seen = [[False]*W for _ in range(H)]
            while len(stk) > 0:
                l = stk.pop()
                i = l[0]
                j = l[1]
                ct = l[2]
                seen[i][j] = True
                for k in mv:
                    x = i+k[0]
                    y = j+k[1]
                    if 0 <= x < H and 0 <= y < W and \
                        maps[x][y] == '.' and seen[x][y] == False:
                            stk.appendleft([x, y, ct+1])
            ans = max(ans, ct)
    print(ans)

if __name__=='__main__':
    main()