import copy
from collections import deque
h,w=map(int,input().split())
p=[list("#"*(w+2))]+[list("#"+input()+"#") for i in range(h)]+[list("#"*(w+2))]
b=copy.deepcopy(p)
ans=0
#s0,s1=map(lambda x:int(x)-1,input().split())
#g0,g1=map(lambda x:int(x)-1,input().split())
for i in range(1,h+1):
    for j in range(1,w+1):
        for k in range(1,h+1):
            for z in range(1,w+1):
                p=copy.deepcopy(b)
                if p[i][j]=='.' and p[k][z]=='.':
                    s0,s1=i,j
                    g0,g1=k,z
                    p[s0][s1]=0
                    d=[(1,0),(-1,0),(0,1),(0,-1)]
                    q=deque([[s0,s1]])
                    while q:
                        x,y=q.popleft()
                        for dx,dy in d:
                            if p[x+dx][y+dy]==".":
                                p[x+dx][y+dy]=p[x][y]+1
                                q.append([x+dx,y+dy])
                    if ans<=p[g0][g1]:
                        ans=p[g0][g1]
print(ans)
