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

f=H*W

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





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

    

for i in range(H):

    for j in range(W-1): 

        cnt=W*i+j

        d[cnt+1][cnt]=s[i][j]==s[i][j+1]=="."

        d[cnt][cnt+1]=s[i][j]==s[i][j+1]=="."

       

for i in range(H-1):

    for j in range(W): 

        cnt=W*i+j

        d[cnt][cnt+W]=s[i][j]==s[i+1][j]=="."

        d[cnt+W][cnt]=s[i][j]==s[i+1][j]=="."

        

import numpy as np

from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson

from scipy.sparse import csr_matrix

csr=np.array(d)





ans=-1

k=shortest_path(csr)

for i in range(f):   

    for q in range(f):

            if k[i][q]>=f+1:k[i][q]=-1



    ans=max(ans,max(k[i]))



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

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

G=[["#"]*(W+2) for _ in range(H+2)]



for i in range(H):

    for j in range(W):

        G[i+1][j+1]=s[i][j]



def search(y,x):

    q=[(y,x)]

    d=[[-1]*(W+2) for _ in range(H+2)]

    d[y][x]=0

    while q:

        y1,x1=q.pop(0)

        for y2,x2 in ((y1+1,x1),(y1,x1+1),(y1-1,x1),(y1,x1-1)):

            if G[y2][x2]=="." and d[y2][x2]==-1:

                d[y2][x2]=d[y1][x1]+1

                q.append((y2,x2))

    return max(max(_) for _ in d)



ans=0

for i in range(H):

    for j in range(W):

        if G[i+1][j+1]==".":

            ans=max(search(i+1,j+1),ans)



print(ans)
H, W = list(map(int, input().split()))
f = H * W
d = [[0] * f for _ in range(f)]
s = [eval(input()) for _ in range(H)]
for i in range(H):
    for j in range(W - 1):
        cnt = W * i + j
        d[cnt + 1][cnt] = s[i][j] == s[i][j + 1] == "."
        d[cnt][cnt + 1] = s[i][j] == s[i][j + 1] == "."
for i in range(H - 1):
    for j in range(W):
        cnt = W * i + j
        d[cnt][cnt + W] = s[i][j] == s[i + 1][j] == "."
        d[cnt + W][cnt] = s[i][j] == s[i + 1][j] == "."
import numpy as np
from scipy.sparse.csgraph import (
    shortest_path,
    floyd_warshall,
    dijkstra,
    bellman_ford,
    johnson,
)
from scipy.sparse import csr_matrix

csr = np.array(d)
ans = -1
k = shortest_path(csr)
for i in range(f):
    for q in range(f):
        if k[i][q] >= f + 1:
            k[i][q] = -1
    ans = max(ans, max(k[i]))
print((int(ans)))

H, W = list(map(int, input().split()))
s = [eval(input()) for _ in range(H)]
G = [["#"] * (W + 2) for _ in range(H + 2)]
for i in range(H):
    for j in range(W):
        G[i + 1][j + 1] = s[i][j]


def search(y, x):
    q = [(y, x)]
    d = [[-1] * (W + 2) for _ in range(H + 2)]
    d[y][x] = 0
    while q:
        y1, x1 = q.pop(0)
        for y2, x2 in ((y1 + 1, x1), (y1, x1 + 1), (y1 - 1, x1), (y1, x1 - 1)):
            if G[y2][x2] == "." and d[y2][x2] == -1:
                d[y2][x2] = d[y1][x1] + 1
                q.append((y2, x2))
    return max(max(_) for _ in d)


ans = 0
for i in range(H):
    for j in range(W):
        if G[i + 1][j + 1] == ".":
            ans = max(search(i + 1, j + 1), ans)
print(ans)

-f = H * W -d = [[0] * f for _ in range(f)] +G = [["#"] * (W + 2) for _ in range(H + 2)] -    for j in range(W - 1): -        cnt = W * i + j -        d[cnt + 1][cnt] = s[i][j] == s[i][j + 1] == "." -        d[cnt][cnt + 1] = s[i][j] == s[i][j + 1] == "." -for i in range(H - 1): -        cnt = W * i + j -        d[cnt][cnt + W] = s[i][j] == s[i + 1][j] == "." -        d[cnt + W][cnt] = s[i][j] == s[i + 1][j] == "." -import numpy as np -from scipy.sparse.csgraph import ( -    shortest_path, -    floyd_warshall, -    dijkstra, -    bellman_ford, -    johnson, -) -from scipy.sparse import csr_matrix +        G[i + 1][j + 1] = s[i][j] -csr = np.array(d) -ans = -1 -k = shortest_path(csr) -for i in range(f): -    for q in range(f): -        if k[i][q] >= f + 1: -            k[i][q] = -1 -    ans = max(ans, max(k[i])) -print((int(ans))) + +def search(y, x): +    q = [(y, x)] +    d = [[-1] * (W + 2) for _ in range(H + 2)] +    d[y][x] = 0 +    while q: +        y1, x1 = q.pop(0) +        for y2, x2 in ((y1 + 1, x1), (y1, x1 + 1), (y1 - 1, x1), (y1, x1 - 1)): +            if G[y2][x2] == "." and d[y2][x2] == -1: +                d[y2][x2] = d[y1][x1] + 1 +                q.append((y2, x2)) +    return max(max(_) for _ in d) + + +ans = 0 +for i in range(H): +    for j in range(W): +        if G[i + 1][j + 1] == ".": +            ans = max(search(i + 1, j + 1), ans) +print(ans)