h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j]==".":
            a[i][j]=99999
ans=0
import collections
from copy import deepcopy
direction=[[0,1],[0,-1],[1,0],[-1,0]]
for sh in range(h):
    for sw in range(w):
        tmp=0
        if a[sh][sw]==99999:
            field=deepcopy(a)
            field[sh][sw]=0
            completed=[]
            next_list=collections.deque([[sh,sw]])
            while next_list:
                n=next_list.popleft()
                completed.append(n)
                for dx,dy in direction:
                    ny,nx=n[0]+dy,n[1]+dx
                    if 0<=ny<=h-1 and 0<=nx<=w-1 and field[ny][nx]!="#" and [ny,nx] not in completed:
                        field[ny][nx]=min(field[n[0]][n[1]]+1,field[ny][nx])
                        next_list.append([ny,nx])
            for i in range(h):
                for j in range(w):
                    if field[i][j]!="#":
                        tmp=max(tmp,field[i][j])
            ans=max(ans,tmp)
print(ans)
            