import sys, math, copy
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial

sys.setrecursionlimit(10**7)
H, W = map(int, input().split())
maze = [[c for c in input()] for _ in range(H)]

moves = [[-1, 0], [1, 0], [0, -1], [0, 1]]

def chkcell(maze_copy, h, w):
    if 0<=h and h<H and 0<=w and w<W and maze_copy[h][w]=='.':
        return True

def count_steps(q, maze_copy):
    steps = -1
    while len(q):
#        print('q:', q)
#        print('maze:')
#        for row in maze_copy:
#            print(row)
        steps += 1
        next_cells = []
        cells = q.pop()
        for cell in cells:
            maze_copy[cell[0]][cell[1]] = '#'
            for move in moves:
                newcell = [i+j for i, j in zip(cell, move)]
                if chkcell(maze_copy=maze_copy, h=newcell[0], w=newcell[1]):
                    next_cells.append(newcell)
        if next_cells:
            q.append(next_cells)

#    print('max_step:', steps)
    return steps

res = 0
for i in range(H):
    for j in range(W):
#        print('i, j', i, j)
        if maze[i][j] == '#':
            continue
        q = deque()
        q.append([[i, j]])
#        maze_copy = copy.deepcopy(maze)
        maze_copy = [[c for c in row] for row in maze]
        val = count_steps(q, maze_copy)
        if res < val: res = val

print(res)

