#全てのマスに対して、そこからスタートして幅探索で最長を求め、そのうちの最大をとる

from collections import deque

h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
if s==[list('.'*20) for i in range(h)]:
    print(40-2)
else:
    ans=0
    Q=deque()
    vec=[(1,0),(0,1),(-1,0),(0,-1)]
    his=[[False for i in range(w)] for j in range(h)]
    for i in range(h):
        for j in range(w):
            if s[i][j]=='#':
                continue
            Q.append([i,j,0])
            while Q:
                x,y,d=Q.popleft()
                for dx,dy in vec:
                    tx=x+dx
                    ty=y+dy
                    if 0<=tx and tx<h and 0<=ty and ty<w and his[tx][ty]==False and s[tx][ty]=='.':
                        Q.append([tx,ty,d+1])
                        his[x][y]=True
                        ans=max(d+1,ans)
            his=[[False for i in range(w)] for j in range(h)]
    print(ans)