#!/usr/bin/env python3

from scipy.sparse.csgraph import floyd_warshall

INF = float("inf")



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

M = [eval(input()) for _ in [0]*h]

E = [[0]*h*w for _ in [0]*h*w]

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



def point(x, y):

    return w * x + y



for i in range(h):

    for j in range(w):

        if M[i][j] == ".":

            for x, y in D:

                I, J = i + x, j + y

                if w > J >= 0 <= I < h and M[I][J] == ".":

                    E[point(i, j)][point(I, J)] = 1



a = floyd_warshall(E)

print((int(a[a != INF].max())))
from scipy.sparse import*

_,*s=open(0)

r=s+["#"*20]

*g,=eval("[0]*500,"*500)

i=-1

for t in s:

 i+=1;j=0

 for u in t:k=i*20+j;g[k][k+1]=u>'#'<t[j+1];g[k][k+20]=u>'#'<r[i+1][j];j+=1

a=csgraph.johnson(csr_matrix(g),0)

print((int(max(a[a<999]))))
#!/usr/bin/env python3
from scipy.sparse.csgraph import floyd_warshall

INF = float("inf")
h, w = list(map(int, input().split()))
M = [eval(input()) for _ in [0] * h]
E = [[0] * h * w for _ in [0] * h * w]
D = [(1, 0), (0, 1), (-1, 0), (0, -1)]


def point(x, y):
    return w * x + y


for i in range(h):
    for j in range(w):
        if M[i][j] == ".":
            for x, y in D:
                I, J = i + x, j + y
                if w > J >= 0 <= I < h and M[I][J] == ".":
                    E[point(i, j)][point(I, J)] = 1
a = floyd_warshall(E)
print((int(a[a != INF].max())))

from scipy.sparse import *

_, *s = open(0)
r = s + ["#" * 20]
(*g,) = eval("[0]*500," * 500)
i = -1
for t in s:
    i += 1
    j = 0
    for u in t:
        k = i * 20 + j
        g[k][k + 1] = u > "#" < t[j + 1]
        g[k][k + 20] = u > "#" < r[i + 1][j]
        j += 1
a = csgraph.johnson(csr_matrix(g), 0)
print((int(max(a[a < 999]))))

-#!/usr/bin/env python3 -from scipy.sparse.csgraph import floyd_warshall +from scipy.sparse import * -INF = float("inf") -h, w = list(map(int, input().split())) -M = [eval(input()) for _ in [0] * h] -E = [[0] * h * w for _ in [0] * h * w] -D = [(1, 0), (0, 1), (-1, 0), (0, -1)] - - -def point(x, y): -    return w * x + y - - -for i in range(h): -    for j in range(w): -        if M[i][j] == ".": -            for x, y in D: -                I, J = i + x, j + y -                if w > J >= 0 <= I < h and M[I][J] == ".": -                    E[point(i, j)][point(I, J)] = 1 -a = floyd_warshall(E) -print((int(a[a != INF].max()))) +_, *s = open(0) +r = s + ["#" * 20] +(*g,) = eval("[0]*500," * 500) +i = -1 +for t in s: +    i += 1 +    j = 0 +    for u in t: +        k = i * 20 + j +        g[k][k + 1] = u > "#" < t[j + 1] +        g[k][k + 20] = u > "#" < r[i + 1][j] +        j += 1 +a = csgraph.johnson(csr_matrix(g), 0) +print((int(max(a[a < 999]))))