from collections import deque

def bfs(x, y):
    Max = 0
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    start = [x, y]
    distance = [[41]*W for i in range(H)]
    distance[y][x] = 0
    Q = deque()
    Q.append(start)

    while len(Q) != 0:
        p = Q.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            
            if 0 <= nx < W and 0 <= ny < H:
                if Maze[ny][nx]=="." and distance[ny][nx]==41:
                    Q.append([nx, ny])
                    distance[ny][nx] = distance[p[1]][p[0]] + 1
    
    for i in range(H):
        for j in range(W):
            if distance[i][j]!=41 and  distance[i][j] > Max:
                Max = distance[i][j]
    return Max

H, W = map(int, input().split())
Maze = [None]*H
for i in range(H):
    Maze[i] = list(input())

MaxDistance = 0
for i in range(H):
    for j in range(W):
        d = bfs(j, i)
        if d > MaxDistance:
            MaxDistance = d


print(MaxDistance)
