import queue

H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]


def srch(h,w):
    ans = 0
    cnt = [[-1 for _ in range(W)] for _ in range(H)]
    que = queue.Queue()
    li1 = [1,0,-1,0]
    li2 = [0,1,0,-1]
    ans = 0

    que.put([h,w,0])
    cnt[h][w]=0

    while not(que.empty()):
        plc = que.get()
        y = plc[0]
        x = plc[1]
        ans = plc[2]

        for i in range(4):
            ny,nx = y+li1[i], x+li2[i]
            # print(ny,nx)
            if ny>=0 and ny<H and nx>=0 and nx<W and cnt[ny][nx]==-1 and S[ny][nx]==".":
                ans += 1
                cnt[ny][nx]= ans
                que.put([ny,nx,ans])
    return ans


ans = 0

for h in range(H):
    for w in range(W):
        if S[h][w]==".":
            ans = max(ans,srch(h,w))
        # print(h,w,ans)

print(ans)

