import copy, collections, itertools

H, W = [int(_) for _ in input().split()]

S_ = [['#'] * (W + 2)] + [['#'] + list(eval(input())) + ['#']

                          for _ in range(H)] + [['#'] * (W + 2)]

ans = 0

for i, j in itertools.product(list(range(1, H + 1)), list(range(1, W + 1))):

    if S_[i][j] == '.':

        S = copy.deepcopy(S_)

        S[i][j] = '#'

        q = collections.deque([(i, j, 0)])

        while q:

            x, y, d = q.popleft()

            for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]:

                if S[x + dx][y + dy] == '.':

                    X, Y = x + dx, y + dy

                    S[X][Y] = '#'

                    q += [(X, Y, d + 1)]

        ans = max(d, ans)

print(ans)

import collections

import numpy as np

from scipy.sparse import csr_matrix

from scipy.sparse.csgraph import floyd_warshall



H, W, *S = open(0).read().split()

H, W = [int(_) for _ in [H, W]]

A = []

B = []

C = []

for i in range(H * W):

    x, y = divmod(i, W)

    if S[x][y] == '.':

        for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):

            nx, ny = x + dx, y + dy

            if not (0 <= nx < H and 0 <= ny < W):

                continue

            if S[nx][ny] == '.':

                A += [i]

                B += [nx * W + ny]

                C += [1]

F = floyd_warshall(csr_matrix((C, (A, B)), shape=(H*W, H*W)))

print((int(np.max(F[F!=np.inf]))))

import copy, collections, itertools

H, W = [int(_) for _ in input().split()]
S_ = (
    [["#"] * (W + 2)]
    + [["#"] + list(eval(input())) + ["#"] for _ in range(H)]
    + [["#"] * (W + 2)]
)
ans = 0
for i, j in itertools.product(list(range(1, H + 1)), list(range(1, W + 1))):
    if S_[i][j] == ".":
        S = copy.deepcopy(S_)
        S[i][j] = "#"
        q = collections.deque([(i, j, 0)])
        while q:
            x, y, d = q.popleft()
            for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
                if S[x + dx][y + dy] == ".":
                    X, Y = x + dx, y + dy
                    S[X][Y] = "#"
                    q += [(X, Y, d + 1)]
        ans = max(d, ans)
print(ans)

import collections
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

H, W, *S = open(0).read().split()
H, W = [int(_) for _ in [H, W]]
A = []
B = []
C = []
for i in range(H * W):
    x, y = divmod(i, W)
    if S[x][y] == ".":
        for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            nx, ny = x + dx, y + dy
            if not (0 <= nx < H and 0 <= ny < W):
                continue
            if S[nx][ny] == ".":
                A += [i]
                B += [nx * W + ny]
                C += [1]
F = floyd_warshall(csr_matrix((C, (A, B)), shape=(H * W, H * W)))
print((int(np.max(F[F != np.inf]))))

-import copy, collections, itertools +import collections +import numpy as np +from scipy.sparse import csr_matrix +from scipy.sparse.csgraph import floyd_warshall -H, W = [int(_) for _ in input().split()] -S_ = ( -    [["#"] * (W + 2)] -    + [["#"] + list(eval(input())) + ["#"] for _ in range(H)] -    + [["#"] * (W + 2)] -) -ans = 0 -for i, j in itertools.product(list(range(1, H + 1)), list(range(1, W + 1))): -    if S_[i][j] == ".": -        S = copy.deepcopy(S_) -        S[i][j] = "#" -        q = collections.deque([(i, j, 0)]) -        while q: -            x, y, d = q.popleft() -            for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]: -                if S[x + dx][y + dy] == ".": -                    X, Y = x + dx, y + dy -                    S[X][Y] = "#" -                    q += [(X, Y, d + 1)] -        ans = max(d, ans) -print(ans) +H, W, *S = open(0).read().split() +H, W = [int(_) for _ in [H, W]] +A = [] +B = [] +C = [] +for i in range(H * W): +    x, y = divmod(i, W) +    if S[x][y] == ".": +        for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)): +            nx, ny = x + dx, y + dy +            if not (0 <= nx < H and 0 <= ny < W): +                continue +            if S[nx][ny] == ".": +                A += [i] +                B += [nx * W + ny] +                C += [1] +F = floyd_warshall(csr_matrix((C, (A, B)), shape=(H * W, H * W))) +print((int(np.max(F[F != np.inf]))))