H, W = map(int, input().split())

maze = [["."for i in range(W)] for j in range(H)]

for h in range(H):
    ret = input()
    for i, x in enumerate(ret):
        if x == "#":
            maze[h][i] = "#"
        # else: # == "."
        #     maze[h][i] = True

# print(maze)

def bfs(maze, y, x):
    q = [[y, x]]
    res = 0
    dist = [[-1] * W for j in range(H)]
    dist[y][x] = 0
    while len(q) > 0:
        yy, xx = q[0]
        res = max(res, dist[yy][xx])
        q.pop(0)
        for dy, dx in [[1,0], [0,1], [-1,0], [0,-1]]:
            ny = yy + dy
            nx = xx + dx
            if nx < 0 or ny < 0 or nx >= W or ny >= H:
                continue
            if maze[ny][nx] == '#':
                continue
            if dist[ny][nx] == -1:
                dist[ny][nx] = dist[yy][xx] + 1
                q.append([ny, nx])
    return res

res_max = 0
for j in range(H):
    for i in range(W):
        res_max = max(res_max, bfs(maze, j, i))
print(res_max)
