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

s = []

for i in range(h):

	ss = eval(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))
from collections import deque

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

s = []

for i in range(h):

	t = eval(input())

	s.append(t)



res = 0

dx = [1,0,-1,0]

dy = [0,1,0,-1]

for i in range(h):

	for j in range(w):

		if s[i][j] == "#":

			continue

		queue = deque([[i,j]])

		visited = [[0 for ii in range(w)] for jj in range(h)]

		visited[i][j] = 1

		while queue:

			l,m = queue.popleft()

			for k in range(4):

				x = l + dx[k]

				y = m + dy[k]

				if x < 0 or y < 0 or x >= h or y >= w or visited[x][y] != 0 or s[x][y] == "#":

					continue

				visited[x][y] = visited[l][m] + 1

				queue.append([x,y])

		for ii in range(h):

			for jj in range(w):

				res = max(res,visited[ii][jj])

print((res-1))
h, w = list(map(int, input().split()))
s = []
for i in range(h):
    ss = eval(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))

from collections import deque

h, w = list(map(int, input().split()))
s = []
for i in range(h):
    t = eval(input())
    s.append(t)
res = 0
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            continue
        queue = deque([[i, j]])
        visited = [[0 for ii in range(w)] for jj in range(h)]
        visited[i][j] = 1
        while queue:
            l, m = queue.popleft()
            for k in range(4):
                x = l + dx[k]
                y = m + dy[k]
                if (
                    x < 0
                    or y < 0
                    or x >= h
                    or y >= w
                    or visited[x][y] != 0
                    or s[x][y] == "#"
                ):
                    continue
                visited[x][y] = visited[l][m] + 1
                queue.append([x, y])
        for ii in range(h):
            for jj in range(w):
                res = max(res, visited[ii][jj])
print((res - 1))

+from collections import deque + -    ss = eval(input()) -    s.append(ss) +    t = eval(input()) +    s.append(t) +res = 0 -ans = 0 +        queue = deque([[i, j]]) -        st = [[i, j]] -        while st: -            x, y = st.pop(0) +        while queue: +            l, m = queue.popleft() -                p = x + dx[k] -                q = y + dy[k] +                x = l + dx[k] +                y = m + dy[k] -                    p < 0 -                    or q < 0 -                    or p >= h -                    or q >= w -                    or s[p][q] == "#" -                    or visited[p][q] != 0 +                    x < 0 +                    or y < 0 +                    or x >= h +                    or y >= w +                    or visited[x][y] != 0 +                    or s[x][y] == "#" -                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)) +                visited[x][y] = visited[l][m] + 1 +                queue.append([x, y]) +        for ii in range(h): +            for jj in range(w): +                res = max(res, visited[ii][jj]) +print((res - 1))