from collections import deque

from itertools import chain



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

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

inf = float('inf')





def flatten(list_of_lists):

    return chain.from_iterable(list_of_lists)





def bfs(start, end):

    distance = [[inf for i in range(W)] for j in range(H)]

    queue = deque([(end, start)])

    distance[end][start] = 0



    while queue:

        y, x = queue.pop()

        for i in range(0, 4):

            nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]

            if 0 <= nx < W and 0 <= ny < H and M[ny][nx] != '#' and distance[ny][nx] == inf:

                queue.appendleft((ny, nx))

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

    return distance





m = 0

for i in range(W):

    for j in range(H):

        if M[j][i] != "#":



            for length in list(flatten(bfs(i, j))):

                if length != inf and m < length:

                    m = length



print(m)

from collections import deque

from itertools import chain



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

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

inf = float('inf')





def flatten(list_of_lists):

    return chain.from_iterable(list_of_lists)





def bfs(start, end):

    distance = [[inf for _ in range(W)] for _ in range(H)]

    queue = deque([(end, start)])

    distance[end][start] = 0



    while queue:

        y, x = queue.pop()

        for i in range(0, 4):

            nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]

            if 0 <= nx < W and 0 <= ny < H and M[ny][nx] != '#' and distance[ny][nx] == inf:

                queue.appendleft((ny, nx))

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

    return distance





m = 0

for i in range(W):

    for j in range(H):

        if M[j][i] != "#":



            for length in list(flatten(bfs(i, j))):

                if length != inf and m < length:

                    m = length



print(m)

from collections import deque
from itertools import chain

H, W = list(map(int, input().split()))
M = [list(eval(input())) for _ in range(H)]
inf = float("inf")


def flatten(list_of_lists):
    return chain.from_iterable(list_of_lists)


def bfs(start, end):
    distance = [[inf for i in range(W)] for j in range(H)]
    queue = deque([(end, start)])
    distance[end][start] = 0
    while queue:
        y, x = queue.pop()
        for i in range(0, 4):
            nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
            if (
                0 <= nx < W
                and 0 <= ny < H
                and M[ny][nx] != "#"
                and distance[ny][nx] == inf
            ):
                queue.appendleft((ny, nx))
                distance[ny][nx] = distance[y][x] + 1
    return distance


m = 0
for i in range(W):
    for j in range(H):
        if M[j][i] != "#":
            for length in list(flatten(bfs(i, j))):
                if length != inf and m < length:
                    m = length
print(m)

from collections import deque
from itertools import chain

H, W = list(map(int, input().split()))
M = [list(eval(input())) for _ in range(H)]
inf = float("inf")


def flatten(list_of_lists):
    return chain.from_iterable(list_of_lists)


def bfs(start, end):
    distance = [[inf for _ in range(W)] for _ in range(H)]
    queue = deque([(end, start)])
    distance[end][start] = 0
    while queue:
        y, x = queue.pop()
        for i in range(0, 4):
            nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
            if (
                0 <= nx < W
                and 0 <= ny < H
                and M[ny][nx] != "#"
                and distance[ny][nx] == inf
            ):
                queue.appendleft((ny, nx))
                distance[ny][nx] = distance[y][x] + 1
    return distance


m = 0
for i in range(W):
    for j in range(H):
        if M[j][i] != "#":
            for length in list(flatten(bfs(i, j))):
                if length != inf and m < length:
                    m = length
print(m)

-    distance = [[inf for i in range(W)] for j in range(H)] +    distance = [[inf for _ in range(W)] for _ in range(H)]