H, W = map(int,input().split())
S = []
for i in range(H):
    S.append(input())

di = [-1,0,1,0]
dj = [0,-1,0,1]

def BFS(i,j,que):
    count = 0
    for k in range(4):
        row = i + di[k]
        col = j + dj[k]
        if H > row >=0 and W >col >= 0 \
            and dist[row][col] == float('inf')\
                and S[row][col] != "#":
            
            que.append([row,col])
            dist[row][col] = dist[i][j] + 1
            count = dist[row][col]
    return count


path_max = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            break
        que = []
        stt = [i,j]
        que.append(stt)
        dist = [[float('inf') for ii in range(W)] for jj in range(H)]
        dist[i][j] = 0
        while que:
            idx = que[0]
            que.pop(0)
            count  = BFS(idx[0],idx[1],que)
            path_max = max(path_max,count)

print(path_max)