import sys

def input():
    return sys.stdin.readline()[:-1]

H,W = map(int,input().split(' '))
MAP = [None]*H
for i in range(H):
    MAP[i] = list(input())




ANS = 0
for i in range(H):
    for j in range(W):
        st = MAP[i][j]
        if st=='.':
            MAX = [0]

            cnt_MAP = [None]*H

            for m in range(H):
                cnt_MAP[m] = [-1 for _ in range(W)]

            def dfs(h,w,cnt):
                if (not (0<=h<H)) or (not (0<=w<W)):
                    return
                if MAP[h][w]=='#':
                    return

                cnt += 1
                if cnt_MAP[h][w]==-1 or cnt_MAP[h][w]>cnt:
                    cnt_MAP[h][w] = cnt
                else:
                    return

                dfs(h+1,w,cnt)
                dfs(h-1,w,cnt)
                dfs(h,w+1,cnt)
                dfs(h,w-1,cnt)

            dfs(i,j,-1)
            tmp = 0
            for i in range(H):
                tmp = max(tmp,max(cnt_MAP[i]))
            ANS = max(ANS,tmp)

print(ANS)