import numpy as np
from collections import deque
h,w=map(int,input().split())
s=[input()for _ in range(h)]
a=np.full((h,w),400,np.int64)
ans=0
def bfs(b,i,j,s):
    b[i,j]=0
    seen=np.zeros((h,w),np.int64)
    todo=deque([(i,j)])
    while np.sum(seen)<h*w and len(todo)>0:
        x,y=todo.popleft()
        if seen[x,y]==1:
            continue
        seen[x,y]=1
        if x>0 and seen[x-1,y]==0 and s[x-1][y]=='.':
            b[x-1,y]=b[x,y]+1
            todo.append((x-1,y))
        if x>0 and s[x-1][y]=='#':
            seen[x-1,y]=1
        if x<h-1 and seen[x+1,y]==0 and s[x+1][y]=='.':
            b[x+1,y]=b[x,y]+1
            todo.append((x+1,y))
        if x<h-1 and s[x+1][y]=='#':
            seen[x+1,y]=1
        if y>0 and seen[x,y-1]==0 and s[x][y-1]=='.':
            b[x,y-1]=b[x,y]+1
            todo.append((x,y-1))
        if y>0 and s[x][y-1]=='#':
            seen[x,y-1]=1
        if y<w-1 and seen[x,y+1]==0 and s[x][y+1]=='.':
            b[x,y+1]=b[x,y]+1
            todo.append((x,y+1))
        if y<w-1 and s[x][y+1]=='#':
            seen[x,y+1]=1
    return np.max(b[b<400])

for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            b=a
            ans=max(ans,bfs(b,i,j,s))
print(ans)
