import collections
def BFS(xNow,yNow,stage,visit):
    dist = [[0] * len(stage[0]) for i in range(len(stage))]
    deq = collections.deque()
    deq.append([xNow,yNow])
    cnt = 0
    while len(deq):
        [xNow,yNow] = deq.popleft()
        visit[xNow][yNow] = 1
        if stage[xNow+1][yNow] != "#" and visit[xNow+1][yNow] == 0:
            deq.append([xNow+1,yNow])
            dist[xNow+1][yNow] = dist[xNow][yNow] + 1
        if stage[xNow-1][yNow] != "#" and visit[xNow-1][yNow] == 0:
            deq.append([xNow-1,yNow])
            dist[xNow-1][yNow] = dist[xNow][yNow] + 1
        if stage[xNow][yNow+1] != "#" and visit[xNow][yNow+1] == 0:
            deq.append([xNow,yNow+1])
            dist[xNow][yNow+1] = dist[xNow][yNow] + 1
        if stage[xNow][yNow-1] != "#" and visit[xNow][yNow-1] == 0:
            deq.append([xNow,yNow-1])
            dist[xNow][yNow-1] = dist[xNow][yNow] + 1
    res = -1
    for i in range(len(dist)):
        res = max(res,max(dist[i]))
        #print(*dist[i])
    return res

[h,w] = [int(i) for i in input().split()]
s = [["#"] * (w+2)]
for i in range(h):
    tmp = input()
    tmp_ls = ["#"]
    for j in range(len(tmp)):
        tmp_ls.append(tmp[j])
    tmp_ls.append("#")
    s.append(tmp_ls)
s.append(["#"] * (w+2))

ans = -1
for i in range(1,h+1):
    for j in range(1,w+1):
        visited = [[0] * (w+2) for i in range(h+2)]
        if s[i][j] == ".":
            ans = max(ans,BFS(i,j,s,visited))
print(ans)
