import numpy as np
from collections import deque
h,w=map(int,input().split())
meiro = [list(input()) for i in range(h)]
#meiro[y][x]
def bfs(a,b):#縦横,0<a<h-1, 0<b<w-1
    maxdist=0
    da=[1,-1,0,0]
    db=[0,0,1,-1]
    dist=[[-1]*w for i in range(h)]
    dist[a][b]=0
    stack=deque([(a,b)])
    while stack:
        y,x=stack.popleft()
        D=dist[y][x]
        for dy,dx in zip(da,db):
            X=x+dx
            Y=y+dy
            if 0<=Y and Y<=h-1 and X<=w-1 and 0<=X:
                if meiro[Y][X]=='.':
                    if dist[Y][X]==-1:
                        dist[Y][X]=D+1
                        stack.append((Y,X))
                    elif dist[Y][X]>0:
                        dist[Y][X]=min(dist[Y][X],D+1)
                else:
                    dist[Y][X]==-(10**6)
    return dist
saidai=0
for i in range(h):
    for j in range(w):
        saidai=max(saidai,np.array(bfs(i,j)).max())
print(saidai)