adjust_list = ((0,1),(0,-1),(1,0),(-1,0))
h, w = [int(v) for v in input().split()]
field = [list(input()) for i in range(h)]

def bfs(s, t):
    si, sj = s
    ti, tj = t
    search_field = [ [ -1 for i in range(w) ] for j in range(h) ]
    search_list = [s]
    turn = 0
    search_field[si][sj] = turn
    
    
    while search_list:
        turn += 1
        new_search_list = []
        for p in search_list:
            pi, pj = p
            
            for q in adjust_list:
                qi, qj = q
                if 0 <= pi+qi < h and 0 <= pj+qj < w:
                    if search_field[pi+qi][pj+qj] == -1 and field[pi+qi][pj+qj] == ".":
                        new_search_list.append((pi+qi,pj+qj))
                        search_field[pi+qi][pj+qj] = turn
        search_list = new_search_list

    return search_field[ti][tj]
    

ans = 0
coodinate = [ (i, j) for i in range(h) for j in range(w) ]
k = h*w

for i in range(k-1):
    for j in range(i+1, k):
        ans = max(ans, bfs(coodinate[i], coodinate[j]))
print(ans)