import sys
input = sys.stdin.readline
#from itertools import permutations

def gcd(a: int, b: int):
    """ https://cocodrips.hateblo.jp/entry/2014/03/05/143623
    """
    while b: a, b = b, a%b
    return a

def lcm(a: int, b: int):
    return a * b // gcd(a, b)


def main():
    #N = int(input())
    H,W = map(int, input().split())
    #vP = tuple(map(int, input().split()))
    #vA = list(map(int, input().split()))
    #vA = list(range(1,N+1))
    mM = [input().rstrip() for _ in [0,]*H]
    vD = [(1,0),(0,1),(-1,0),(0,-1)]

    INF = 1001001001

    def dij(x,y,p,q):
        return x+y+p+q

    def dijA(x,y,p,q):
        if (x,y)==(p,q): return 0
        mP = [[INF,]*W for _ in [0,]*H]
        #print(mP[p][q], file=sys.stderr)
        mV = [[False,]*W for _ in [0,]*H]
        vQ = []
        vQ.append((x,y))
        mP[x][y] = 0
        while vQ:
            xt,yt = vQ.pop()
            #if (xt,yt)==(p,q): break
            for xd,yd in vD:
                if (not 0<=xt+xd<H) or (not 0<=yt+yd<W):
                    continue
                if mM[xt+xd][yt+yd]!="#":
                    mP[xt+xd][yt+yd] = min(mP[xt][yt]+1, mP[xt+xd][yt+yd])
                    #print(mP[][])
                    if mV[xt+xd][yt+yd]==False:
                        mV[xt+xd][yt+yd] = True
                        vQ.append((xt+xd,yt+yd))
                    
        return mP[p][q]

    #print(dijA(1,0,1,4)); return


    res = 0
    for a in range(H):
        for b in range(W):
            if mM[a][b]=="#": continue
            for c in range(H):
                for d in range(W):
                    if mM[c][d]=="#": continue
                    tmp = dijA(a,b,c,d)
                    res = max(res, tmp)
    print(res)

    #print(l, file=sys.stderr)
    #l //= 2
    #S = input().rstrip()
    #print(S)
    #print(chr(ord(S)+1))
    #print(lcm(N, M))
    #print("Yes" if N<=500*M else "No")
    #print(S.count("ABC"))


if __name__ == "__main__":
    main()
