def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

from copy import deepcopy
import itertools

h,w=n1()
s=s2(h)
s=["#"+x+"#" for x in s]
s=["#"*(w+2)]+s+["#"*(w+2)]
meiro_original=[[0]*(w+2) for _ in range(h+2)]
road=[]
for i in range(len(s)):
    for j in range(len(s[i])):
        if s[i][j]=="#":
            meiro_original[i][j]=2
        else:
            meiro_original[i][j]=0
            road.append([i,j])

def calc(start):
    ans=0
    meiro=deepcopy(meiro_original)
    pos=[[start[0],start[1],0]]
    while len(pos)>0:
        x,y,c=pos.pop(0)

        meiro[x][y]=2

        f=False
        if meiro[x-1][y]<2:
            pos.append([x-1,y,c+1])
            f=True
        if meiro[x+1][y]<2:
            pos.append([x+1,y,c+1])
            f=True
        if meiro[x][y-1]<2:
            pos.append([x,y-1,c+1]) 
            f=True
        if meiro[x][y+1]<2:
            pos.append([x,y+1,c+1])
            f=True
        if f==False:
            ans=max(ans,c)   
    return ans

l=0
for line in road:
    x,y=line
    if meiro_original[x-1][y]==meiro_original[x+1][y]==0 or meiro_original[x][y-1]==meiro_original[x][y+1]==0:
        pass
    else:
        l=max(l,calc(line))
    
print(l)  