H, W = map(int, input().split())

move = [[0 for i in range(W)]for i in range(H)]

S = ["#" for i in range(H)]

M = 0

for i in range(H):
    S[i] = input()





def keisoku(sx,sy,ex,ey):
    global W
    global H
    end = False

    count = 1

    kyori = [[-1 for i in range(W)]for i in range(H)]
    kyori[ey][ex] == 0
    if ey < H-1:
        
        if S[ey+1][ex] == ".":
            kyori[ey+1][ex] = 1
    if ey >= 1:
        if S[ey-1][ex] == ".":
            kyori[ey-1][ex] = 1
    if ex < W -1:
            
        if S[ey][ex+1] == ".":
            kyori[ey][ex+1] = 1
    if ex >= 1:
        if S[ey][ex-1] == ".":
            kyori[ey][ex-1] = 1

    while(not end):
        for x in range(W):
            for y in range(H):
                if kyori[y][x] == count:
                    
                    if y < H -1:
                            
                        if S[y+1][x] == ".":
                            kyori[y+1][x] = count +1
                    if y >= 1:
                            
                        if S[y-1][x] == ".":
                            kyori[y-1][x] = count +1
                    if x < W -1:
                            
                        if S[y][x+1] == ".":
                            kyori[y][x+1] = count +1

                    if x >= 1:
                            
                        if S[y][x-1] == ".":
                            kyori[y][x-1] = count +1

        
        if kyori[sy][sx] != -1:
            end = True
        count += 1
    
    return kyori[sy][sx]
                    
for sx in range(W):
    for sy in range(H):
        for ex in range(W):
            for ey in range(H):
                if S[sy][sx] == "#" or S[ey][ex] == "#" or (sx == ex and sy == ey):
                    continue

                newmax = keisoku(sx,sy,ex,ey)
                if newmax > M:
                    M = newmax 

print(M)

