#!/usr/bin/python3
#coding: utf-8
#bootcamp

from collections import defaultdict

H, W = (int(i) for i in input().split())

MAZE = []
for i in range(H):
    MAZE.append(list(input()))

INF = 10**10
d = [[INF] * H*W for _ in range(H*W)]
for i in range(H):
    for j in range(W):
        if MAZE[i][j] == '#' : continue
        node = i * W + j
        for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)):
            ni = i + di
            nj = j + dj
            if 0 <= ni < H and 0 <= nj < W and MAZE[ni][nj] == '.':
                next_node = ni * W + nj
                d[node][next_node] = 1
                d[next_node][node] = 1

for k in range(H*W):
    for i in range(H*W):
        for j in range(H*W):
            d[i][j] =  min(d[i][j], d[i][k] + d[k][j])

ret = 0
for i in range(H*W):
    for j in range(H*W):
        if d[i][j] == INF: continue
        ret = max(ret, d[i][j])
print(ret)
