
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 Gh in range(H):
    for Gw in range(W):
        if S[Gh][Gw]=="#":continue
        for h in range(H):
            for w in range(W):
                if Gh==h and Gw==w:continue
                if S[h][w]=="#":continue
                chk=deepcopy(S)
                q=deque([[h,w,0]])
                chk[h][w]=1
                f=True
                while q and f:
                    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])
                            mx=max(mx,c)
                            if y+dh==Gh and x+dw==Gw:
                                f=False
                                break

print(mx)


