import queue
import copy
import numpy as np

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

maze = []
maze.append(["#" for i in range(W+2)])
for i in range(H):
    maze.append(list(input()))
    maze[i+1].insert(0,"#")
    maze[i+1].append("#")
maze.append(["#" for i in range(W+2)])

distance_template = np.array([[-1 for i in range(W+2)] for i in range(H+2)])

ans = 0
for i in range(1,H+1):
    for j in range(1,W+1):
        cnt = 0
        for k in range(0, 4):
            nx, ny = i + [1, 0, -1, 0][k], j + [0, 1, 0, -1][k]
            if maze[nx][ny] != "#":
                cnt+=1
                if cnt == 4:
                    continue
        if maze[i][j] != "#":
            startx,starty = i,j
            distance = copy.deepcopy(distance_template)
            distance[startx][starty] = 0
            Q = queue.Queue()
            Q.put((startx, starty))
            while not Q.empty():
                x,y = Q.get()
                for k in range(0, 4):
                    nx, ny = x + [1, 0, -1, 0][k], y + [0, 1, 0, -1][k]
                    if (maze[nx][ny] != "#" and distance[nx][ny] == -1):
                        Q.put((nx, ny))
                        distance[nx][ny] = distance[x][y] + 1
            maxdistance = np.unravel_index(np.argmax(distance), distance.shape)
            if ans < distance[maxdistance[0]][maxdistance[1]]:
                ans = distance[maxdistance[0]][maxdistance[1]]
print(ans)

