import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readlines

def main():

    INFTY = 10000
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    lines = input()

    H, W = list(map(int, lines[0].split()))
    v = H * W
    P = [] #kaku tennno joukyou
    for i in range(1, H+1):
        asa = lines[i].split()[0]
        P.append(asa)

    A = [[INFTY] * v for i in range(v)]
    #shokika
    for vi in range(v):
        x = vi % W ; y = vi // W
        if P[y][x] == '#':
            continue
        for i in range(4):#4方向
            nx = x + dx[i] ; ny = y + dy[i]
            if nx < 0 or nx == W or ny < 0 or ny == H :
                continue
            if P[ny][nx] == '#':
                continue

            A[vi][nx+ny*W] = 1
    
    ## Floyd-Warshall
    for k in range(v):
        for i in range(v):
            if A[i][k] == INFTY:
                continue
            for j in range(v):
                if A[k][j] == INFTY:
                    continue
                a = A[i][j]
                b = A[i][k] + A[k][j]
                if a > b:
                    A[i][j] = b

    ## max search
    res = 0
    for vi in range(v):
        x = vi % W ; y = vi // W
        if P[y][x] == '#':
            continue
        for vj in range(v):
            c = A[vi][vj]
            if c > 5000:
                continue
            if c > res:
                res = c

    print(res)

main()

