#bfs(両端キュー)
from collections import deque
import copy

h,w=map(int, input().split())
d=[list(input()) for i in range(h)]
inf=10**7

def bfs(sx,sy):
    a=copy.deepcopy(d)
    for i in range(h):
        for j in range(w):
            if a[i][j]=='.':
                a[i][j]=inf
    que=deque([[sy,sx]])
    a[sy][sx]=0

    while que:
        y,x=que.popleft()
        for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
            ny,nx=y+i,x+j
            if nx>=0 and nx<w and ny>=0 and ny<h:
                dist=a[ny][nx]
                if dist!='#':
                    if dist>a[y][x]+1:
                        a[ny][nx]=a[y][x]+1
                        que.append([ny,nx])

    m=0
    for i in range(h):
        for j in range(w):
            if a[i][j]!='#':
                if a[i][j]>m:
                    m=a[i][j]
    return m
    
# BFSのstartを決める
ans=0
for i in range(h):
    for j in range(w):
        if ans<bfs(j,i):
            ans=bfs(j,i)
print(ans)