import sys
input = sys.stdin.readline

H,W=map(int,input().split())
S=[input().strip() for i in range(H)]
from collections import deque

def bfs(x,y):
    

    Q=deque()
    Q.append((x,y))
    count=[[0]*W for i in range(H)]

    while Q:
        x,y=Q.pop()
        for z,w in [(x+1,y),(x-1,y),(x,y-1),(x,y+1)]:
            if 0<=z<H and 0<=w<W and count[z][w]==0 and S[z][w]==".":
                count[z][w]=count[x][y]+1
                Q.appendleft((z,w))

    return max([max(c) for c in count])

ANS=0

for i in range(H):
    for j in range(W):
        ANS=max(ANS,bfs(i,j))

print(ANS)
        