import queue

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

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



dxs = [0, 0, 1, -1]

dys = [1, -1, 0, 0]

cand = []

for j in range(H):

    for i in range(W):

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

            continue

        q = queue.Queue()

        q.put((i, j, 0))

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

        field[j][i] = 0

        while not q.empty():

            p = q.get()

            for dx, dy in zip(dxs, dys):

                x, y = p[0] + dx, p[1] + dy

                if not (0 <= x < W) or not (0 <= y < H) or S[y][x] == '#' or field[y][x] != -1:

                    continue

                field[y][x] = p[2] + 1

                q.put((x, y, p[2] + 1))

        cand.append(max(max(row) for row in field))

print((max(cand)))
from collections import deque

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

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



dxs = [0, 0, 1, -1]

dys = [1, -1, 0, 0]

cand = []

for j in range(H):

    for i in range(W):

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

            continue

        q = deque()

        q.append((i, j, 0))

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

        field[j][i] = 0

        while q:

            p = q.popleft()

            for dx, dy in zip(dxs, dys):

                x, y = p[0] + dx, p[1] + dy

                if not (0 <= x < W) or not (0 <= y < H) or S[y][x] == '#' or field[y][x] != -1:

                    continue

                field[y][x] = p[2] + 1

                q.append((x, y, p[2] + 1))

        cand.append(max(max(row) for row in field))

print((max(cand)))
import queue

H, W = list(map(int, input().split()))
S = [list(eval(input())) for _ in range(H)]
dxs = [0, 0, 1, -1]
dys = [1, -1, 0, 0]
cand = []
for j in range(H):
    for i in range(W):
        if S[j][i] == "#":
            continue
        q = queue.Queue()
        q.put((i, j, 0))
        field = [[-1] * W for _ in range(H)]
        field[j][i] = 0
        while not q.empty():
            p = q.get()
            for dx, dy in zip(dxs, dys):
                x, y = p[0] + dx, p[1] + dy
                if (
                    not (0 <= x < W)
                    or not (0 <= y < H)
                    or S[y][x] == "#"
                    or field[y][x] != -1
                ):
                    continue
                field[y][x] = p[2] + 1
                q.put((x, y, p[2] + 1))
        cand.append(max(max(row) for row in field))
print((max(cand)))

from collections import deque

H, W = list(map(int, input().split()))
S = [list(eval(input())) for _ in range(H)]
dxs = [0, 0, 1, -1]
dys = [1, -1, 0, 0]
cand = []
for j in range(H):
    for i in range(W):
        if S[j][i] == "#":
            continue
        q = deque()
        q.append((i, j, 0))
        field = [[-1] * W for _ in range(H)]
        field[j][i] = 0
        while q:
            p = q.popleft()
            for dx, dy in zip(dxs, dys):
                x, y = p[0] + dx, p[1] + dy
                if (
                    not (0 <= x < W)
                    or not (0 <= y < H)
                    or S[y][x] == "#"
                    or field[y][x] != -1
                ):
                    continue
                field[y][x] = p[2] + 1
                q.append((x, y, p[2] + 1))
        cand.append(max(max(row) for row in field))
print((max(cand)))

-import queue +from collections import deque -        q = queue.Queue() -        q.put((i, j, 0)) +        q = deque() +        q.append((i, j, 0)) -        while not q.empty(): -            p = q.get() +        while q: +            p = q.popleft() -                q.put((x, y, p[2] + 1)) +                q.append((x, y, p[2] + 1))