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

l = [eval(input()) for i in range(H)]



from collections import deque

d = [(1, 0), (-1, 0), (0, 1), (0, -1)]



ans = 0

for i in range(H):

    for j in range(W):

        if l[i][j] == '#':

            continue

        ll = [[0] * W for _ in range(H)]

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

        while q:

            y, x = q.popleft()

            for dy, dx in d:

                if 0 <= y+dy < H and 0 <= x+dx < W and l[y+dy][x+dx] == '.' and (y+dy, x+dx) != (i, j):

                    n = ll[y][x] + 1

                    if ll[y+dy][x+dx] == 0 or ll[y+dy][x+dx] > n:

                        ll[y+dy][x+dx] = n

                        q.append((y+dy, x+dx))

                        if ans < n:

                            ans = n



print(ans)
H, W = list(map(int, input().split()))

l = [eval(input()) for i in range(H)]

 

from collections import deque

d = [(1, 0), (-1, 0), (0, 1), (0, -1)]



ans = 0

for i in range(H):

    for j in range(W):

        if l[i][j] == '#':

            continue

        cells = [[None] * W for _ in range(H)]

        cells[i][j] = 0

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

        while q:

            y, x = q.popleft()

            for dy, dx in d:

                if 0 <= y+dy < H and 0 <= x+dx < W and l[y+dy][x+dx] == '.' and (cells[y+dy][x+dx] is None or cells[y+dy][x+dx] > cells[y][x]+1):

                    n = cells[y][x] + 1

                    cells[y+dy][x+dx] = n

                    q.append((y+dy, x+dx))

                    if ans < n:

                        ans = n



print(ans)
H, W = list(map(int, input().split()))
l = [eval(input()) for i in range(H)]
from collections import deque

d = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans = 0
for i in range(H):
    for j in range(W):
        if l[i][j] == "#":
            continue
        ll = [[0] * W for _ in range(H)]
        q = deque([(i, j)])
        while q:
            y, x = q.popleft()
            for dy, dx in d:
                if (
                    0 <= y + dy < H
                    and 0 <= x + dx < W
                    and l[y + dy][x + dx] == "."
                    and (y + dy, x + dx) != (i, j)
                ):
                    n = ll[y][x] + 1
                    if ll[y + dy][x + dx] == 0 or ll[y + dy][x + dx] > n:
                        ll[y + dy][x + dx] = n
                        q.append((y + dy, x + dx))
                        if ans < n:
                            ans = n
print(ans)

H, W = list(map(int, input().split()))
l = [eval(input()) for i in range(H)]
from collections import deque

d = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans = 0
for i in range(H):
    for j in range(W):
        if l[i][j] == "#":
            continue
        cells = [[None] * W for _ in range(H)]
        cells[i][j] = 0
        q = deque([(i, j)])
        while q:
            y, x = q.popleft()
            for dy, dx in d:
                if (
                    0 <= y + dy < H
                    and 0 <= x + dx < W
                    and l[y + dy][x + dx] == "."
                    and (
                        cells[y + dy][x + dx] is None
                        or cells[y + dy][x + dx] > cells[y][x] + 1
                    )
                ):
                    n = cells[y][x] + 1
                    cells[y + dy][x + dx] = n
                    q.append((y + dy, x + dx))
                    if ans < n:
                        ans = n
print(ans)

-        ll = [[0] * W for _ in range(H)] +        cells = [[None] * W for _ in range(H)] +        cells[i][j] = 0 -                    and (y + dy, x + dx) != (i, j) +                    and ( +                        cells[y + dy][x + dx] is None +                        or cells[y + dy][x + dx] > cells[y][x] + 1 +                    ) -                    n = ll[y][x] + 1 -                    if ll[y + dy][x + dx] == 0 or ll[y + dy][x + dx] > n: -                        ll[y + dy][x + dx] = n -                        q.append((y + dy, x + dx)) -                        if ans < n: -                            ans = n +                    n = cells[y][x] + 1 +                    cells[y + dy][x + dx] = n +                    q.append((y + dy, x + dx)) +                    if ans < n: +                        ans = n