h, w = map(int, input().split())
s = []
for i in range(h):
	ss = input()
	s.append(ss)

dx = [1,0,-1,0]
dy = [0,1,0,-1]
ans = 0
for i in range(h):
	for j in range(w):
		if s[i][j] == "#":
			continue
		visited = [[0 for ii in range(w)] for jj in range(h) ]
		st = [[i,j]]
		visited[i][j] = 1
		while st:
			x,y = st.pop(0)
			for k in range(4):
				p = x + dx[k]
				q = y + dy[k]
				if p < 0 or q < 0 or p >= h or q >= w or s[p][q] == "#" or visited[p][q] != 0:
					continue
				st.append([p,q])
				visited[p][q] = visited[x][y] + 1
		#print (visited)
		for a in range(h):
			for b in range(w):
				ans = max(ans,visited[a][b])
print (ans-1)