import os, sys, re, math


(H, W) = [int(n) for n in input().split()]


def set_moves(x, y, moves):
    if grid[y][x] >= 0 and grid[y][x] < moves:
        return
    grid[y][x] = moves

    if y > 0 and S[y - 1][x] == '.':
        set_moves(x, y - 1, moves + 1)
    if y < (H - 1) and S[y + 1][x] == '.':
        set_moves(x, y + 1, moves + 1)
    if x > 0 and S[y][x - 1] == '.':
        set_moves(x - 1, y, moves + 1)
    if x < (W - 1) and S[y][x + 1] == '.':
        set_moves(x + 1, y, moves + 1)


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

result = 0

for gy in range(H):
    for gx in range(W):
        grid = []
        for i in range(H):
            grid.append([-1] * W)
        set_moves(gx, gy, 0)

        result = max(result, max([max(row) for row in grid]))

print(result)
