h, w = map(int, input().split())

s = ['']*(h+2)

s[0] = "#"*(w+2)
s[h+1] = "#"*(w+2)

for i in range(1,h+1):
	s[i] = '#'+input()+'#'

dn = [[0]*(w+2) for i in range(h+2)]

cnt = 0 

for i in range(1, h+1):
	for j in range(1, w+1):
		if s[i][j] == '.':
			dn[i][j] = cnt
			cnt += 1

d = [[float('inf')]*cnt for i in range(cnt)]

for i in range(1, h+1):
	for j in range(1, w+1):
		if s[i][j] == '.':
			if s[i-1][j] == '.':
				d[dn[i][j]][dn[i-1][j]] = 1
			if s[i+1][j] == '.':
				d[dn[i][j]][dn[i+1][j]] = 1
			if s[i][j-1] == '.':
				d[dn[i][j]][dn[i][j-1]] = 1
			if s[i][j+1] == '.':
				d[dn[i][j]][dn[i][j+1]] = 1
			d[dn[i][j]][dn[i][j]] = 0	

for k in range(cnt):
	for i in range(cnt):
		for j in range(cnt):
			d[i][j] = min(d[i][j],d[i][k] + d[k][j])

ans = 0
for i in range(cnt):
	ans = max(max(d[i]),ans)

print(ans)