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

s="#"*W+"".join("#"+eval(input()) for _ in range(H))

f=(W+1)*(H+1)

d=[[0]*f for _ in range(f)]

for i in range(W,f-1):

 d[i][i-1]=s[i]==s[i-1]=="."

 d[i][i-W-1]=s[i]==s[i-W-1]=="."

from scipy.sparse.csgraph import csgraph_from_dense as C,floyd_warshall as F

Q=F(C(d),directed=False)

r=-1

for q in Q:

 for x in q:

  if f>x:

   r=max(r,int(x))

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

s="#"*W+"".join("#"+eval(input())for _ in range(H))

f=-~W*-~H

d=[[0]*f for _ in range(f)]

for i in range(W,f-1):

 d[i][i-1]=s[i]==s[i-1]=="."

 d[i][i-W-1]=s[i]==s[i-W-1]=="."

from scipy.sparse.csgraph import csgraph_from_dense as C,floyd_warshall as F

import numpy as p

Q=F(C(d),directed=False)

print((int(max(Q[Q!=p.inf]))))
H, W = list(map(int, input().split()))
s = "#" * W + "".join("#" + eval(input()) for _ in range(H))
f = (W + 1) * (H + 1)
d = [[0] * f for _ in range(f)]
for i in range(W, f - 1):
    d[i][i - 1] = s[i] == s[i - 1] == "."
    d[i][i - W - 1] = s[i] == s[i - W - 1] == "."
from scipy.sparse.csgraph import csgraph_from_dense as C, floyd_warshall as F

Q = F(C(d), directed=False)
r = -1
for q in Q:
    for x in q:
        if f > x:
            r = max(r, int(x))
print(r)

H, W = list(map(int, input().split()))
s = "#" * W + "".join("#" + eval(input()) for _ in range(H))
f = -~W * -~H
d = [[0] * f for _ in range(f)]
for i in range(W, f - 1):
    d[i][i - 1] = s[i] == s[i - 1] == "."
    d[i][i - W - 1] = s[i] == s[i - W - 1] == "."
from scipy.sparse.csgraph import csgraph_from_dense as C, floyd_warshall as F
import numpy as p

Q = F(C(d), directed=False)
print((int(max(Q[Q != p.inf]))))

-f = (W + 1) * (H + 1) +f = -~W * -~H +import numpy as p -r = -1 -for q in Q: -    for x in q: -        if f > x: -            r = max(r, int(x)) -print(r) +print((int(max(Q[Q != p.inf]))))