
from collections import deque
from copy import deepcopy


H,W=map(int,input().split())
S=[]
for i in range(H):
    temp=list(input())
    S.append(temp)

step=[[1,0],[-1,0],[0,1],[0,-1]]

mx=0
for h in range(H):
    for w in range(W):
        if S[h][w]=="#":continue
        chk=deepcopy(S)
        q=deque([[h,w,0]])
        chk[h][w]="#"
        while q:
            y,x,c=q.popleft()
            for dh,dw in step:
                if y+dh<0 or y+dh>=H:continue
                if x+dw<0 or x+dw>=W:continue
                if chk[y+dh][x+dw]==".":
                    c+=1
                    chk[y+dh][x+dw]="#"
                    q.append([y+dh,x+dw,c])
                else:
                    mx=max(mx,c)

print(mx)


