# coding: utf-8
# Your code here!
import sys
from collections import deque
h,w=map(int,input().split())
grid=[]
for i in range(h):
    arr=list(input())
    grid.append(arr)
    
trans=[[0,1],[0,-1],[1,0],[-1,0]]
ans=0
for a in range(h):
    for b in range(w):
        dist=[[-1]*w for _ in range(h)]
        d=deque()
        d.append((a,b))
        dist[a][b]=0

        while d:
            i,j=d.popleft()
            for s,t in trans:
                x,y=i+s,j+t
                if x>=h or x<0 or y>=w or y<0 or grid[x][y]=="#" or dist[x][y]!=-1:
                    continue
                dist[x][y]=dist[i][j]+1
                d.append((x,y))
        ans=max(ans,max(list(map(lambda x: max(x), dist))))
print(ans)
