import copy
import numpy as np
from collections import deque

h, w = map(int,input().split())

maze_o = [0]*h
for i in range(h):
    maze_o[i] = list(input())

dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
#すべての "." をスタート位置にする
ans = 0
for y in range(h):
    for x in range(w):
        if maze_o[y][x] == "#":
            continue
        maze = copy.deepcopy(maze_o)
        distance = np.array([[0]*w for _ in range(h)])
        stack = deque([(y, x)])
        while stack:
            yy, xx = stack.pop()
            maze[yy][xx] = "#"
            for dxi, dyi in zip(dx, dy):
                if not (0<=xx+dxi<w and 0<=yy+dyi<h):
                    continue
                if maze[dyi+yy][dxi+xx] == "#":
                    continue
                if distance[dyi+yy][dxi+xx] != 0:
                    distance[dyi+yy][dxi+xx] = min(distance[dyi+yy][dxi+xx], distance[yy][xx] + 1)
                else:
                    distance[dyi+yy][dxi+xx] = distance[yy][xx] + 1
                stack.append((dyi+yy, dxi+xx))
        ans = max(ans, np.max(distance))
print(ans)