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



S = [[True]*(W+2)]

S += [[True] + [x == '#' for x in input().rstrip()] + [True] for _ in range(H)]

S.append([True]*(W+2))



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

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



edge = []

for i in range(1,H+1):

    for j in range(1,W+1):

        if S[i][j]:

            continue

        for d in range(4):

            x = dx[d]

            y = dy[d]

            if (not S[i+y][j+x]) and (not ((i+y-1)*W+(j+x),(i-1)*W+j) in edge):

                edge.append(((i-1)*W+j,(i+y-1)*W+(j+x)))



S = [[float("inf")] * (H*W) for _ in range(H*W)]

for i in range(H*W):

    S[i][i] = 0

for a,b in edge:

    S[a-1][b-1] = 1

    S[b-1][a-1] = 1



from scipy.sparse.csgraph import floyd_warshall

S = floyd_warshall(S)



answer = 0

for i in range(H*W):

    for j in range(i):

        if S[i][j] < float("inf"):

            answer = max(answer, S[i][j])



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

S = [["#"] * (W + 2)]

S += [["#"] + list(eval(input())) + ["#"] for _ in range(H)]

S.append(["#"] * (W + 2))



DX = [0,0,-1,1]

DY = [-1,1,0,0]



from collections import deque



def bfs(y,x):

    dist = [[-1] * (W + 2) for _ in range(H + 2)] 

    

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

    dist[y][x] = 0

    while que:

        y, x = que.popleft()

        d = dist[y][x]

        for dy,dx in zip(DY,DX):

            ny, nx = y + dy, x + dx

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

            if dist[ny][nx] < 0:

                dist[ny][nx] = d + 1

                que.append((ny,nx))

    

    ans = -1

    for i in range(1, H + 1):

        for j in range(1, W + 1):

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

    return ans



ans = 0

for i in range(1, H + 1):

    for j in range(1, W + 1):

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

        ans = max(ans, bfs(i, j))



print(ans)
H, W = list(map(int, input().split()))
S = [[True] * (W + 2)]
S += [[True] + [x == "#" for x in input().rstrip()] + [True] for _ in range(H)]
S.append([True] * (W + 2))
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
edge = []
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j]:
            continue
        for d in range(4):
            x = dx[d]
            y = dy[d]
            if (not S[i + y][j + x]) and (
                not ((i + y - 1) * W + (j + x), (i - 1) * W + j) in edge
            ):
                edge.append(((i - 1) * W + j, (i + y - 1) * W + (j + x)))
S = [[float("inf")] * (H * W) for _ in range(H * W)]
for i in range(H * W):
    S[i][i] = 0
for a, b in edge:
    S[a - 1][b - 1] = 1
    S[b - 1][a - 1] = 1
from scipy.sparse.csgraph import floyd_warshall

S = floyd_warshall(S)
answer = 0
for i in range(H * W):
    for j in range(i):
        if S[i][j] < float("inf"):
            answer = max(answer, S[i][j])
print((int(answer)))

H, W = list(map(int, input().split()))
S = [["#"] * (W + 2)]
S += [["#"] + list(eval(input())) + ["#"] for _ in range(H)]
S.append(["#"] * (W + 2))
DX = [0, 0, -1, 1]
DY = [-1, 1, 0, 0]
from collections import deque


def bfs(y, x):
    dist = [[-1] * (W + 2) for _ in range(H + 2)]
    que = deque([(y, x)])
    dist[y][x] = 0
    while que:
        y, x = que.popleft()
        d = dist[y][x]
        for dy, dx in zip(DY, DX):
            ny, nx = y + dy, x + dx
            if S[ny][nx] == "#":
                continue
            if dist[ny][nx] < 0:
                dist[ny][nx] = d + 1
                que.append((ny, nx))
    ans = -1
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            ans = max(ans, dist[i][j])
    return ans


ans = 0
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] == "#":
            continue
        ans = max(ans, bfs(i, j))
print(ans)

-S = [[True] * (W + 2)] -S += [[True] + [x == "#" for x in input().rstrip()] + [True] for _ in range(H)] -S.append([True] * (W + 2)) -dx = [0, 0, 1, -1] -dy = [1, -1, 0, 0] -edge = [] +S = [["#"] * (W + 2)] +S += [["#"] + list(eval(input())) + ["#"] for _ in range(H)] +S.append(["#"] * (W + 2)) +DX = [0, 0, -1, 1] +DY = [-1, 1, 0, 0] +from collections import deque + + +def bfs(y, x): +    dist = [[-1] * (W + 2) for _ in range(H + 2)] +    que = deque([(y, x)]) +    dist[y][x] = 0 +    while que: +        y, x = que.popleft() +        d = dist[y][x] +        for dy, dx in zip(DY, DX): +            ny, nx = y + dy, x + dx +            if S[ny][nx] == "#": +                continue +            if dist[ny][nx] < 0: +                dist[ny][nx] = d + 1 +                que.append((ny, nx)) +    ans = -1 +    for i in range(1, H + 1): +        for j in range(1, W + 1): +            ans = max(ans, dist[i][j]) +    return ans + + +ans = 0 -        if S[i][j]: +        if S[i][j] == "#": -        for d in range(4): -            x = dx[d] -            y = dy[d] -            if (not S[i + y][j + x]) and ( -                not ((i + y - 1) * W + (j + x), (i - 1) * W + j) in edge -            ): -                edge.append(((i - 1) * W + j, (i + y - 1) * W + (j + x))) -S = [[float("inf")] * (H * W) for _ in range(H * W)] -for i in range(H * W): -    S[i][i] = 0 -for a, b in edge: -    S[a - 1][b - 1] = 1 -    S[b - 1][a - 1] = 1 -from scipy.sparse.csgraph import floyd_warshall - -S = floyd_warshall(S) -answer = 0 -for i in range(H * W): -    for j in range(i): -        if S[i][j] < float("inf"): -            answer = max(answer, S[i][j]) -print((int(answer))) +        ans = max(ans, bfs(i, j)) +print(ans)