import math
H, W = [int(i) for i in input().split()]
SSS = [[math.inf for i in range(W+2)]]
for i in range(H):
    buff = "#"+input()+"#"
    SSS.append([0 if i=="." else math.inf for i in buff])
SSS.append([math.inf for i in range(W+2)])

def routetable(x0,y0):
    table = [[10000000 for i in range(W+2)] for j in range(H+2)]
    for i in range(H+2):
        for j in range(W+2):
            if SSS[i][j]==math.inf:
                table[i][j]=SSS[i][j]
    table[x0][y0]=1

    
    while True:
        detector = 0
        for i in range(1,H+1):
            for j in range(1,W+1):
                if table[i][j]==10000000: detector += 1
                if table[i-1][j]!=math.inf: table[i-1][j]=min(table[i][j]+1,table[i-1][j])
                if table[i+1][j]!=math.inf: table[i+1][j]=min(table[i][j]+1,table[i+1][j])
                if table[i][j-1]!=math.inf: table[i][j-1]=min(table[i][j]+1,table[i][j-1])
                if table[i][j+1]!=math.inf: table[i][j+1]=min(table[i][j]+1,table[i][j+1])
        if detector==0:
            break
    """
    print("\n")
    for t in table:
        print(t)
    """
    maxroute = 0
    for i in range(H+2):
        for j in range(W+2):
            if table[i][j]!=math.inf:
                maxroute = max(maxroute,table[i][j])
    return(maxroute-1)


ans = 0
for i in range(1,H+1):
    for j in range(1,W+1):
        if SSS[i][j]!=math.inf:
            ans = max(ans,routetable(i,j))

print(ans)