import collections
H,W = map(int,input().split())
LL=[]
for i in range(H):
    LL.append(input())
    
L = ((1,0),(0,1),(-1,0),(0,-1))
q = collections.deque()
max_L = []
for i in range(H):
    for j in range(W):
        d = [[0]*W for i in range(H)]
        if LL[i][j] ==".":
            q.append((i,j))
            d[i][j] = 0
            max1 = 0
            while q:
                x,y = q.popleft()
                for dx,dy in L:
                    if 0>x+dx or x+dx>H-1 or 0>y+dy or y+dy>W-1 or d[x+dx][y+dy] !=0:
                        continue
                    if  LL[x+dx][y+dy] == ".":
                        d[x+dx][y+dy] = d[x][y] +1
                        q.append((x+dx,y+dy))
                        max1 = max(max1,d[x+dx][y+dy])
                        max_L.append(max1)
                        #print(q,d ,max1)
print(max(max_L))
