from scipy.sparse import*

_,*s=open(0)

M=999

*g,=eval('[0]*M,'*M)

i=0

for t in s:

 i+=1;j=0

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

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

print((int(max(a[a<M]))))
from scipy.sparse import*

_,*s=open(i:=0)

M=999

*g,=eval('[0]*M,'*M)

for t in s:

 i+=1;j=0

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

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

print((int(max(a[a<M]))))
from scipy.sparse import *

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

from scipy.sparse import *

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

-_, *s = open(0) +_, *s = open(i := 0) -i = 0