import queue
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

    qx = queue.Queue()
    qy = queue.Queue()


    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
            qx.put(ex)
            qy.put(ey+1)
    if ey >= 1:
        if S[ey-1][ex] == ".":
            kyori[ey-1][ex] = 1
            qx.put(ex)
            qy.put(ey-1)
    if ex < W -1:
            
        if S[ey][ex+1] == ".":
            kyori[ey][ex+1] = 1
            qx.put(ex+1)
            qy.put(ey)
    if ex >= 1:
        if S[ey][ex-1] == ".":
            kyori[ey][ex-1] = 
            qx.put(ex-1)
            qy.put(ey)

    while(not end):
        x = qx.get()
        y = qy.get()
        
        if y < H -1:
                
            if S[y+1][x] == ".":
                qx.put(x)
                qy.put(y+1)
                kyori[y+1][x] = kyori[y][x]+1
        if y >= 1:
                
            if S[y-1][x] == ".":
                qx.put(x)
                qy.put(y-1)
                kyori[y-1][x] = kyori[y][x]+1
        if x < W -1:
                
            if S[y][x+1] == ".":
                qx.put(x+1)
                qy.put(y)
                kyori[y][x+1] =  kyori[y][x]+1

        if x >= 1:
                
            if S[y][x-1] == ".":
                qx.put(x-1)
                qy.put(y)
                kyori[y][x-1] = kyori[y][x]+1

        
        if kyori[sy][sx] != -1:
            end = True
    
    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)

