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