from collections import deque
INF = 5000
vx = [-1,0,1,0]
vy = [0,-1,0,1]

H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]

d = [-1] * (H*W)
xy = lambda x,y: x + y*W

ds = []
for sx in range(W):
    for sy in range(H):
        q = deque([(sx,sy)])
        tmpd = d.copy()
        tmpd[xy(sx,sy)] = 0
        while(q):
            x,y = q.popleft()
            for i in range(4):
                nx = x + vx[i]
                ny = y + vy[i]
                if 0 <= nx and nx < W and 0 <= ny and ny < H and S[ny][nx] != '#' and tmpd[xy(nx,ny)] == -1:
                    q.append((nx,ny))
                    tmpd[xy(nx,ny)] = tmpd[xy(x,y)] + 1
        ds.append(max(tmpd))
print(max(ds))