H, W = map(int, input().split())

n_list = []
v_table = {}
for y in range(H):
	for x in range(W):
		n = (x, y)
		n_list.append(n)
		v_table[n] = []

prev = None
ns = None
for y in range(H):
	cur = input()
	for x in range(W):
		if cur[x] == ".":
			nc = (x, y)
			ns = nc
			if y > 0 and prev[x] == ".":
				np = (x, (y - 1))
				v_table[np].append(nc)
				v_table[nc].append(np)
			if x > 0 and cur[x - 1] == ".":
				np = (x - 1, y)
				v_table[np].append(nc)
				v_table[nc].append(np)
	prev = cur

def find_farthest(x, n_list, edges):
	dists = { x: 0 }
	queue = [ x ]
	
	while queue:
		cur = queue.pop()
		dist = dists[cur] + 1
		for v2 in edges[cur]:
			if (not v2 in dists) or (dists[v2] > dist):
				dists[v2] = dist
				queue.append(v2)
	farthest = (x, 0)
	for n in n_list:
		if n in dists and farthest[1] < dists[n]:
			farthest = (n, dists[n])
	
	return farthest

f1 = find_farthest(ns, n_list, v_table)
f2 = find_farthest(f1[0], n_list, v_table)
print(f2[1])



