# coding: utf-8
# Your code here!
from collections import deque

H,W=map(int,input().split())


def bfs(h,w,n):
    yoyaku=[]
    if h>0:
        if lis[h-1][w]>n+1 and mp[h-1][w]!="#":
            yoyaku.append([h-1,w,n+1])
    if w>0:
        if lis[h][w-1]>n+1 and mp[h][w-1]!="#":
            yoyaku.append([h,w-1,n+1])
    if h<H-1:
        if lis[h+1][w]>n+1 and mp[h+1][w]!="#":
            yoyaku.append([h+1,w,n+1])
    if w<W-1:
        if lis[h][w+1]>n+1 and mp[h][w+1]!="#":
            yoyaku.append([h,w+1,n+1])
    
    lis[h][w]=min(n,lis[h][w])
    return yoyaku

    

mp=[]
for _ in range(H):
    mp.append(list(input()))

ans=[]

for h in range(H):
    for w in range(W):
        lis=[[1000]*W for i in range(H)]
        que=deque([[[h,w,0]]]) if mp[h][w]!="#" else []
        pre=0
        while True:
            if len(que)==0:
                break
            else:
                temp=que.pop()
                #print(temp)
                for tem in temp:
                    pre=max(pre,tem[2])
                    que.append(bfs(tem[0],tem[1],tem[2]))
                    
        pre=0
        for item in lis:
            for tem in item:
                pre=max(pre,tem)    
        ans.append(pre)
    
print(max(ans))