import numpy as np
import sys

h,w = map(int,input().split())
maze = [list(input()) for i in range(h)]

def clear_maze(sx, sy, maze):

    INF = 0

    field_y_length = len(maze)
    field_x_length = len(maze[0])
    distance = [[INF for i in range(field_x_length)] for j in range(field_y_length)]

    def bfs():
        queue = []

        queue.insert(0, (sy, sx))

        distance[sy][sx] = 0

        while len(queue):
            x, y = queue.pop()

            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]

                if (0 <= nx and nx < field_y_length and 0 <= ny and ny < field_x_length and maze[nx][ny] != '#' and distance[nx][ny] == INF):
                    queue.insert(0, (nx, ny))
                    distance[nx][ny] = distance[x][y] + 1
        return max(distance)

    return bfs()

ans = [0 for i in range(h*w)]

for i in range(h):
    for j in range(w):
        if maze[i][j]=='.':
            sx = j
            sy = i
            ans[i*w+j]=clear_maze(sx,sy,maze)
temp = 0
t1 = 0
for i in ans:
    if i!=0:
        temp = max(i)
        t1 = max(temp,t1)
print(t1)