# import bisect
# import copy
# import fractions
# import math
import numpy as np
from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    H, W = map(int, input().split())
    maze = [input() for _ in range(H)]

    def bfs(maze, visited, sy, sx):
        queue = deque([[sy, sx]])

        visited[sy][sx] = 0
        while queue:
            y, x = queue.popleft()
            for dy, dx in ([1, 0], [-1, 0], [0, 1], [0, -1]):
                ny, nx = y + dy, x + dx
                if 0<=ny<H and 0<=nx<W and \
                        maze[ny][nx] == "." and visited[ny][nx] == -1:
                    visited[ny][nx] = visited[y][x] + 1
                    queue.append([ny, nx])
        return np.amax(visited)

    ans=-1
    for i in range(H):
        for j in range(W):
            visited = [[-1] * W for _ in range(H)]

            sy,sx=i,j
            if maze[sy][sx]=='.':
                ans = max(ans,bfs(maze, visited, sy, sx))


    print(ans)
resolve()