from collections import deque







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

S = [eval(input()) for _ in range(H)]



ans = 0

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

for i in range(H):

    for j in range(W):

        if S[i][j] == "#": continue

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

        visited = [[False for _ in range(W)] for _ in range(H)]

        visited[i][j] = True

        q = deque()

        q.append((i,j))

        while q:

            y,x = q.popleft()

            for dy,dx in dyx:

                ny, nx = y+dy, x+dx

                if not 0 <= ny <= H-1 or not 0 <= nx <= W-1 or visited[ny][nx] == True or S[ny][nx] == "#":

                    continue

                q.append((ny, nx))

                dist[ny][nx] = dist[y][x] + 1

                visited[ny][nx] = True





        ans = max(ans, max(max(row) for row in dist))



            



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

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



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

from collections import deque

ans = 0

for y in range(H):

    for x in range(W):

        if S[y][x] == '#': continue

        dist = [[0]*W for i in range(H)]

        visited = [[0]*W for i in range(H)]

        visited[y][x] = 1

        q = deque([(x,y)])

        while q:

            x,y = q.popleft()

            for dx,dy in dxy:

                nx,ny = x+dx,y+dy

                if not 0 <= nx < W: continue

                if not 0 <= ny < H: continue

                if visited[ny][nx]: continue

                if S[ny][nx] == '#': continue

                visited[ny][nx] = 1

                dist[ny][nx] = dist[y][x] + 1

                q.append((nx,ny))





        for i in range(H):

            ans = max(ans, max(dist[i]))

        #ans = max(ans, max(max(row) for row in dist))

print(ans)



from collections import deque

H, W = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
ans = 0
dyx = [(1, 0), (0, 1), (-1, 0), (0, -1)]
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        dist = [[0 for _ in range(W)] for _ in range(H)]
        visited = [[False for _ in range(W)] for _ in range(H)]
        visited[i][j] = True
        q = deque()
        q.append((i, j))
        while q:
            y, x = q.popleft()
            for dy, dx in dyx:
                ny, nx = y + dy, x + dx
                if (
                    not 0 <= ny <= H - 1
                    or not 0 <= nx <= W - 1
                    or visited[ny][nx] == True
                    or S[ny][nx] == "#"
                ):
                    continue
                q.append((ny, nx))
                dist[ny][nx] = dist[y][x] + 1
                visited[ny][nx] = True
        ans = max(ans, max(max(row) for row in dist))
print(ans)

H, W = list(map(int, input().split()))
S = [eval(input()) for i in range(H)]
dxy = [(0, 1), (1, 0), (0, -1), (-1, 0)]
from collections import deque

ans = 0
for y in range(H):
    for x in range(W):
        if S[y][x] == "#":
            continue
        dist = [[0] * W for i in range(H)]
        visited = [[0] * W for i in range(H)]
        visited[y][x] = 1
        q = deque([(x, y)])
        while q:
            x, y = q.popleft()
            for dx, dy in dxy:
                nx, ny = x + dx, y + dy
                if not 0 <= nx < W:
                    continue
                if not 0 <= ny < H:
                    continue
                if visited[ny][nx]:
                    continue
                if S[ny][nx] == "#":
                    continue
                visited[ny][nx] = 1
                dist[ny][nx] = dist[y][x] + 1
                q.append((nx, ny))
        for i in range(H):
            ans = max(ans, max(dist[i]))
        # ans = max(ans, max(max(row) for row in dist))
print(ans)

+H, W = list(map(int, input().split())) +S = [eval(input()) for i in range(H)] +dxy = [(0, 1), (1, 0), (0, -1), (-1, 0)] -H, W = list(map(int, input().split())) -S = [eval(input()) for _ in range(H)] -dyx = [(1, 0), (0, 1), (-1, 0), (0, -1)] -for i in range(H): -    for j in range(W): -        if S[i][j] == "#": +for y in range(H): +    for x in range(W): +        if S[y][x] == "#": -        dist = [[0 for _ in range(W)] for _ in range(H)] -        visited = [[False for _ in range(W)] for _ in range(H)] -        visited[i][j] = True -        q = deque() -        q.append((i, j)) +        dist = [[0] * W for i in range(H)] +        visited = [[0] * W for i in range(H)] +        visited[y][x] = 1 +        q = deque([(x, y)]) -            y, x = q.popleft() -            for dy, dx in dyx: -                ny, nx = y + dy, x + dx -                if ( -                    not 0 <= ny <= H - 1 -                    or not 0 <= nx <= W - 1 -                    or visited[ny][nx] == True -                    or S[ny][nx] == "#" -                ): +            x, y = q.popleft() +            for dx, dy in dxy: +                nx, ny = x + dx, y + dy +                if not 0 <= nx < W: -                q.append((ny, nx)) +                if not 0 <= ny < H: +                    continue +                if visited[ny][nx]: +                    continue +                if S[ny][nx] == "#": +                    continue +                visited[ny][nx] = 1 -                visited[ny][nx] = True -        ans = max(ans, max(max(row) for row in dist)) +                q.append((nx, ny)) +        for i in range(H): +            ans = max(ans, max(dist[i])) +        # ans = max(ans, max(max(row) for row in dist))