H,W=map(int,input().split())
S=[[1 if c=='#' else 0 for c in input()] for i in range(H)]
from collections import deque
r=0
for i in range(H):
    for j in range(W):
        if S[i][j]==1:
            continue
        d=[[0]*W for i in range(H)]
        q=deque([(i,j,0)])
        while q:
            x,y,d0=q.popleft()
            if x>0 and S[x-1][y]==d[x-1][y]==0:
                q.append((x-1,y,d0+1))
                d[x-1][y]=d0+1
            if y>0 and S[x][y-1]==d[x][y-1]==0:
                q.append((x,y-1,d0+1))
                d[x][y-1]=d0+1
            if x<H-1 and S[x+1][y]==d[x+1][y]==0:
                q.append((x+1,y,d0+1))
                d[x+1][y]=d0+1
            if y<W-1 and S[x][y+1]==d[x][y+1]==0:
                q.append((x,y+1,d0+1))
                d[x][y+1]=d0+1
        r=max(r,d0)
print(r)