from collections import deque
H,W = map(int,input().split())
S = list()
for i in range(H):
    S.append(list(input()))
mx = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        q = deque([(i,j,0)])
        T = [[S[k][l] for l in range(W)] for k in range(H)]
        T[i][j] = "#"
        while q:
            x,y,c = q.popleft()
            for dx, dy in [(0,1),(0,-1),(1,0),(-1,0)]:
                nx,ny = x+dx,y+dy
                if 0 <= nx < H and 0 <= ny < W and T[nx][ny] == ".":
                    T[nx][ny] = "#"
                    q.append((nx,ny,c+1))
        mx = max(mx,c)
print(mx)