def main():
	H, W = [int(x) for x in input().split(" ")]
	S = []
	S.append(["X"] * (W + 2))
	h = 0
	w = 0
	for i in range(H):
		row = list(input())
		S.append(["X"] + row + ["X"])
		if not h and not w and row.count(".") > 0:
			h = i + 1
			w = row.index(".") + 1
	S.append(["X"] * (W + 2))

	m = BFS(S, h, w, H + 2, W + 2)
	tmp = {"row": -1, "col": -1, "max": 0}
	for i in range(len(m)):
		for j in range(len(m[i])):
			if m[i][j] > tmp["max"]:
				tmp["row"] = i
				tmp["col"] = j
				tmp["max"] = m[i][j]
	q = BFS(S, tmp["row"], tmp["col"], H + 2, W + 2)
	ans = []
	for i in range(len(q)):
		ans += q[i]
	print(max(ans))

def BFS(M, i, j, H, W):
	to_visit = [{"row": i, "col": j, "step": 0}]
	checked = [[0] * W for x in range(H)]
	checked[i][j] = 1
	ret = [[0] * W for x in range(H)]
	while len(to_visit):
		visiting = to_visit.pop(0)
		r0 = visiting["row"]
		c0 = visiting["col"]
		s0 = visiting["step"]
		ret[r0][c0] = s0
		for d in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
			r = r0 + d[0]
			c = c0 + d[1]
			s = s0 + 1
			if checked[r][c] == 0 and M[r][c] == ".":
				to_visit.append({"row": r, "col": c, "step": s})
				checked[r][c] = 1
	return ret

main()
