from collections import deque

def bfs(meiro, start_x, start_y):

    visited = []
    for i in range(len(meiro)):
        visited.append([])
        for j in range(len(meiro[i])):
            visited[i].append(0)

    stack = deque()
    stack.append([start_x, start_y])
    visited[start_x][start_y] = 0
    max_distance = 0
    while len(stack) != 0:
        x, y = map(int, stack.popleft())
        distance = visited[x][y]
        if x > 0 and visited[x-1][y] == 0 and meiro[x-1][y] == ".":
            stack.append([x-1, y])
            visited[x-1][y] = distance+1
            if max_distance < distance+1:
                max_distance = distance+1
        if y > 0 and visited[x][y-1] == 0 and meiro[x][y-1] == ".":
            stack.append([x, y-1])
            visited[x][y-1] = distance+1
            if max_distance < distance + 1:
                max_distance = distance + 1
        if x < H-1 and visited[x+1][y] == 0 and meiro[x+1][y] == ".":
            stack.append([x+1, y])
            visited[x+1][y] = distance+1
            if max_distance < distance + 1:
                max_distance = distance + 1
        if y < W-1 and visited[x][y+1] == 0 and meiro[x][y+1] == ".":
            stack.append([x, y+1])
            visited[x][y+1] = distance+1
            if max_distance < distance + 1:
                max_distance = distance + 1
    return max_distance

H, W = map(int, input().split())
meiro = []
for h in range(H):
    meiro.append(list(input()))

max_distance = 0
for h in range(H):
    for w in range(W):
        if meiro[h][w] == ".":
            dis = bfs(meiro, h, w)
            if max_distance < dis:
                max_distance = dis
print(max_distance)
