from collections import deque

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

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

direction = [[0, 1], [1, 0], [0, -1], [-1, 0]]



ans = 0

for sh in range(H):

    for sw in range(W):

        if maze[sh][sw] == "#":

            continue



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

        dist[sh][sw] = 0

        que = deque([[sh, sw]])



        while que:

            nh, nw = que.pop()

            for dh, dw in direction:

                if not ((0 <= nh + dh < H) and (0 <= nw + dw < W)):

                    continue

                if maze[nh + dh][nw + dw] == "#":

                    continue

                if dist[nh + dh][nw + dw] != -1:

                    continue



                dist[nh + dh][nw + dw] = dist[nh][nw] + 1

                que.appendleft([nh + dh, nw + dw])



        ans = max(ans, max([max(d) for d in dist]))



print(ans)
from collections import deque

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

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

directions = [[0, 1], [1, 0], [0, -1], [-1, 0]]



ans = 0

for sh in range(H):

    for sw in range(W):

        if maze[sh][sw] == "#":

            continue

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

        dist[sh][sw] = 0

        que = deque([[sh, sw]])



        while que:

            nh, nw = que.pop()

            for dh, dw in directions:

                tmp_h, tmp_w = nh + dh, nw + dw

                if not ((0 <= tmp_h < H) and (0 <= tmp_w < W)):

                    continue

                if maze[tmp_h][tmp_w] == "#":

                    continue

                if dist[tmp_h][tmp_w] != -1:

                    continue



                dist[tmp_h][tmp_w] = dist[nh][nw] + 1

                que.appendleft([tmp_h, tmp_w])



        ans = max(ans, max([max(d) for d in dist]))



print(ans)
from collections import deque

H, W = list(map(int, input().split()))
maze = [list(eval(input())) for _ in range(H)]
direction = [[0, 1], [1, 0], [0, -1], [-1, 0]]
ans = 0
for sh in range(H):
    for sw in range(W):
        if maze[sh][sw] == "#":
            continue
        dist = [[-1] * W for _ in range(H)]
        dist[sh][sw] = 0
        que = deque([[sh, sw]])
        while que:
            nh, nw = que.pop()
            for dh, dw in direction:
                if not ((0 <= nh + dh < H) and (0 <= nw + dw < W)):
                    continue
                if maze[nh + dh][nw + dw] == "#":
                    continue
                if dist[nh + dh][nw + dw] != -1:
                    continue
                dist[nh + dh][nw + dw] = dist[nh][nw] + 1
                que.appendleft([nh + dh, nw + dw])
        ans = max(ans, max([max(d) for d in dist]))
print(ans)

from collections import deque

H, W = list(map(int, input().split()))
maze = [list(eval(input())) for _ in range(H)]
directions = [[0, 1], [1, 0], [0, -1], [-1, 0]]
ans = 0
for sh in range(H):
    for sw in range(W):
        if maze[sh][sw] == "#":
            continue
        dist = [[-1] * W for _ in range(H)]
        dist[sh][sw] = 0
        que = deque([[sh, sw]])
        while que:
            nh, nw = que.pop()
            for dh, dw in directions:
                tmp_h, tmp_w = nh + dh, nw + dw
                if not ((0 <= tmp_h < H) and (0 <= tmp_w < W)):
                    continue
                if maze[tmp_h][tmp_w] == "#":
                    continue
                if dist[tmp_h][tmp_w] != -1:
                    continue
                dist[tmp_h][tmp_w] = dist[nh][nw] + 1
                que.appendleft([tmp_h, tmp_w])
        ans = max(ans, max([max(d) for d in dist]))
print(ans)

-direction = [[0, 1], [1, 0], [0, -1], [-1, 0]] +directions = [[0, 1], [1, 0], [0, -1], [-1, 0]] -            for dh, dw in direction: -                if not ((0 <= nh + dh < H) and (0 <= nw + dw < W)): +            for dh, dw in directions: +                tmp_h, tmp_w = nh + dh, nw + dw +                if not ((0 <= tmp_h < H) and (0 <= tmp_w < W)): -                if maze[nh + dh][nw + dw] == "#": +                if maze[tmp_h][tmp_w] == "#": -                if dist[nh + dh][nw + dw] != -1: +                if dist[tmp_h][tmp_w] != -1: -                dist[nh + dh][nw + dw] = dist[nh][nw] + 1 -                que.appendleft([nh + dh, nw + dw]) +                dist[tmp_h][tmp_w] = dist[nh][nw] + 1 +                que.appendleft([tmp_h, tmp_w])