h,w=map(int,input().split())
s=[list(input()) for _ in range(h)]
dyx=[(1,0),(-1,0),(0,1),(0,-1)]
from collections import deque
q=deque()
ans=0
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            continue
        q.append((i,j))
        d=[[0]*w for _ in range(h)]
        while q:
            y,x=q.popleft()
            for dy,dx in dyx:
                ny,nx=y+dy,x+dx
                if ny==i and nx==j:
                    continue
                if 0<=ny<h and 0<=nx<w and d[ny][nx]==0 and s[ny][nx]==".":
                    d[ny][nx]=d[y][x]+1
                    q.append((ny,nx))
        for k in range(h):
            ans=max(ans,max(d[k]))
print(ans)
