import numpy as np

from collections import deque

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

s =["#"*(w+2)] + ["#" + str(eval(input())) + "#" for i in range(h)] + ["#"*(w+2)]

s = np.array(s)

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

ans = 0



for i in range(1,h+1):

    for j in range(1,w+1):

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

            temp = [[0]*(w+2) for i in range(h+2)]

            temp[i][j] = 1

            dq = deque([(i,j)])

            

            while dq:

                x,y = dq.popleft()

                for k in opt:

                    x1,y1 = x+k[0],y+k[1]

                    if s[x1][y1] == "." and temp[x1][y1] == 0:

                        temp[x1][y1] = temp[x][y] + 1

                        dq.append((x1,y1))

            ans = max(ans,np.max(temp))

print((ans-1))
from collections import deque

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

s =["#"*(w+2)] + ["#" + str(eval(input())) + "#" for i in range(h)] + ["#"*(w+2)]

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

ans = 0



for i in range(1,h+1):

    for j in range(1,w+1):

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

            temp = [[0]*(w+2) for i in range(h+2)]

            temp[i][j] = 1

            dq = deque([(i,j)])

            

            while dq:

                x,y = dq.popleft()

                for k in opt:

                    x1,y1 = x+k[0],y+k[1]

                    if s[x1][y1] == "." and temp[x1][y1] == 0:

                        temp[x1][y1] = temp[x][y] + 1

                        dq.append((x1,y1))

                        ans=max(ans,temp[x1][y1])

print((ans-1))
import numpy as np
from collections import deque

h, w = list(map(int, input().split()))
s = (
    ["#" * (w + 2)]
    + ["#" + str(eval(input())) + "#" for i in range(h)]
    + ["#" * (w + 2)]
)
s = np.array(s)
opt = [(1, 0), (0, 1), (-1, 0), (0, -1)]
ans = 0
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == ".":
            temp = [[0] * (w + 2) for i in range(h + 2)]
            temp[i][j] = 1
            dq = deque([(i, j)])
            while dq:
                x, y = dq.popleft()
                for k in opt:
                    x1, y1 = x + k[0], y + k[1]
                    if s[x1][y1] == "." and temp[x1][y1] == 0:
                        temp[x1][y1] = temp[x][y] + 1
                        dq.append((x1, y1))
            ans = max(ans, np.max(temp))
print((ans - 1))

from collections import deque

h, w = list(map(int, input().split()))
s = (
    ["#" * (w + 2)]
    + ["#" + str(eval(input())) + "#" for i in range(h)]
    + ["#" * (w + 2)]
)
opt = [(1, 0), (0, 1), (-1, 0), (0, -1)]
ans = 0
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == ".":
            temp = [[0] * (w + 2) for i in range(h + 2)]
            temp[i][j] = 1
            dq = deque([(i, j)])
            while dq:
                x, y = dq.popleft()
                for k in opt:
                    x1, y1 = x + k[0], y + k[1]
                    if s[x1][y1] == "." and temp[x1][y1] == 0:
                        temp[x1][y1] = temp[x][y] + 1
                        dq.append((x1, y1))
                        ans = max(ans, temp[x1][y1])
print((ans - 1))

-import numpy as np -s = np.array(s) -            ans = max(ans, np.max(temp)) +                        ans = max(ans, temp[x1][y1])