from collections import deque





def solve(S, s):

    if S[s[0]][s[1]] != ".":

        return -1

    queue = deque([s])

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

    visited[s[0]][s[1]] = 0

    while queue:

        y, x = queue.popleft()

        for j, k in ([1,0], [-1,0], [0,1], [0,-1]):

            new_y, new_x = y+j, x+k

            if new_x in range(W) and new_y in range(H) and S[new_y][new_x] == "." and visited[new_y][new_x] == -1:

                visited[new_y][new_x] = visited[y][x] + 1

                queue.append([new_y, new_x])

#    for v in visited:

#        print(v)

    return max(list(map(max,visited)))





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

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

ans = -1

for i in range(H):

    for l in range(W):

        ans = max(ans, solve(S, [i, l]))

print(ans)

from collections import deque

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

s = [[x for x in eval(input())] for _ in range(h)]



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





def bfs(i, j):

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

        return -1

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

    visited = [[-1 for _ in range(w)] for __ in range(h)]

    visited[i][j] = 0

    while q:

        v = q.popleft()

        for d in delta:

            vd1, vd2 = v[0]+d[0], v[1]+d[1]

            if 0 <= vd1 < h and 0 <= vd2 < w:

                if s[vd1][vd2] != '#' and visited[vd1][vd2] == -1:

                    visited[vd1][vd2] = visited[v[0]][v[1]] + 1

                    q.append((vd1, vd2))

    return max(list(map(max, visited)))





ans = 0



for i in range(h):

    for j in range(w):

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



print(ans)

from collections import deque


def solve(S, s):
    if S[s[0]][s[1]] != ".":
        return -1
    queue = deque([s])
    visited = [[-1 for _ in range(W)] for _ in range(H)]
    visited[s[0]][s[1]] = 0
    while queue:
        y, x = queue.popleft()
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y + j, x + k
            if (
                new_x in range(W)
                and new_y in range(H)
                and S[new_y][new_x] == "."
                and visited[new_y][new_x] == -1
            ):
                visited[new_y][new_x] = visited[y][x] + 1
                queue.append([new_y, new_x])
    #    for v in visited:
    #        print(v)
    return max(list(map(max, visited)))


H, W = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
ans = -1
for i in range(H):
    for l in range(W):
        ans = max(ans, solve(S, [i, l]))
print(ans)

from collections import deque

h, w = list(map(int, input().split()))
s = [[x for x in eval(input())] for _ in range(h)]
delta = [(-1, 0), (1, 0), (0, 1), (0, -1)]


def bfs(i, j):
    if s[i][j] == "#":
        return -1
    q = deque([(i, j)])
    visited = [[-1 for _ in range(w)] for __ in range(h)]
    visited[i][j] = 0
    while q:
        v = q.popleft()
        for d in delta:
            vd1, vd2 = v[0] + d[0], v[1] + d[1]
            if 0 <= vd1 < h and 0 <= vd2 < w:
                if s[vd1][vd2] != "#" and visited[vd1][vd2] == -1:
                    visited[vd1][vd2] = visited[v[0]][v[1]] + 1
                    q.append((vd1, vd2))
    return max(list(map(max, visited)))


ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, bfs(i, j))
print(ans)

+h, w = list(map(int, input().split())) +s = [[x for x in eval(input())] for _ in range(h)] +delta = [(-1, 0), (1, 0), (0, 1), (0, -1)] -def solve(S, s): -    if S[s[0]][s[1]] != ".": + +def bfs(i, j): +    if s[i][j] == "#": -    queue = deque([s]) -    visited = [[-1 for _ in range(W)] for _ in range(H)] -    visited[s[0]][s[1]] = 0 -    while queue: -        y, x = queue.popleft() -        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]): -            new_y, new_x = y + j, x + k -            if ( -                new_x in range(W) -                and new_y in range(H) -                and S[new_y][new_x] == "." -                and visited[new_y][new_x] == -1 -            ): -                visited[new_y][new_x] = visited[y][x] + 1 -                queue.append([new_y, new_x]) -    #    for v in visited: -    #        print(v) +    q = deque([(i, j)]) +    visited = [[-1 for _ in range(w)] for __ in range(h)] +    visited[i][j] = 0 +    while q: +        v = q.popleft() +        for d in delta: +            vd1, vd2 = v[0] + d[0], v[1] + d[1] +            if 0 <= vd1 < h and 0 <= vd2 < w: +                if s[vd1][vd2] != "#" and visited[vd1][vd2] == -1: +                    visited[vd1][vd2] = visited[v[0]][v[1]] + 1 +                    q.append((vd1, vd2)) -H, W = list(map(int, input().split())) -S = [eval(input()) for _ in range(H)] -ans = -1 -for i in range(H): -    for l in range(W): -        ans = max(ans, solve(S, [i, l])) +ans = 0 +for i in range(h): +    for j in range(w): +        ans = max(ans, bfs(i, j))