'''input
3 3
...
...
...
'''
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline
from collections import deque


def mp(arr):
	return str(arr[0]) + ' ' + str(arr[1])

def bfs(source, target):
	myq = deque()
	myq.append(mp(source))
	visited = dict()
	visited[mp(source)] = True
	dist = 0
	while len(myq) > 0:
		temp = deque()
		while len(myq) > 0:
			x, y  = list(map(int, myq.popleft().split()))
			if mp([x,y]) == mp(target):
				return dist
			if x - 1 >= 0 and maze[x - 1][y] != '#' and mp([x - 1, y]) not in visited:
				visited[mp([x -1, y])] = True
				temp.append(mp([x - 1, y]))
			if x  + 1 < n and maze[x + 1][y] != '#' and mp([x + 1, y]) not in visited:
				visited[mp([x + 1, y])] = True
				temp.append(mp([x + 1, y]))
			if y - 1 >= 0 and maze[x][y - 1] != '#' and mp([x, y - 1]) not in visited:
				visited[mp([x, y - 1])] = True
				temp.append(mp([x, y - 1]))
			if y + 1 < m and maze[x][y + 1] != '#' and mp([x, y + 1]) not in visited:
				visited[mp([x, y + 1])] = True
				temp.append(mp([x, y + 1]))
		dist += 1
		myq = temp
	return -float('inf')			


# main starts
n, m = list(map(int, input().split()))
maze = []
for _ in range(m):
	state = list(stdin.readline().strip())
	maze.append(state)

ans = -float('inf')
for i in range(n):
	for j in range(m):
		for x in range(n):
			for y in range(m):
				first = [i, j]
				second = [x, y]
				ans = max(ans, bfs(first, second))
print(ans)
