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(h+2):

    for j in range(w+2):

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

        temp[i][j] = 1

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

        

        while dq:

            x,y = dq.popleft()

            if s[x][y] == ".":

                for k in opt:

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

                    if s[x1][y1] == ".":

                        if temp[x1][y1] == 0:

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

                            dq.append((x1,y1))

                        elif temp[x1][y1] > temp[x][y] + 1:

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

                            dq.append((x1,y1))

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

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(h+2):

    for j in range(w+2):

        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))
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(h + 2):
    for j in range(w + 2):
        temp = [[0] * (w + 2) for i in range(h + 2)]
        temp[i][j] = 1
        dq = deque([(i, j)])
        while dq:
            x, y = dq.popleft()
            if s[x][y] == ".":
                for k in opt:
                    x1, y1 = x + k[0], y + k[1]
                    if s[x1][y1] == ".":
                        if temp[x1][y1] == 0:
                            temp[x1][y1] = temp[x][y] + 1
                            dq.append((x1, y1))
                        elif temp[x1][y1] > temp[x][y] + 1:
                            temp[x1][y1] = temp[x][y] + 1
                            dq.append((x1, y1))
        ans = max(ans, np.max(temp))
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(h + 2):
    for j in range(w + 2):
        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))

-        temp = [[0] * (w + 2) for i in range(h + 2)] -        temp[i][j] = 1 -        dq = deque([(i, j)]) -        while dq: -            x, y = dq.popleft() -            if s[x][y] == ".": +        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() -                    if s[x1][y1] == ".": -                        if temp[x1][y1] == 0: -                            temp[x1][y1] = temp[x][y] + 1 -                            dq.append((x1, y1)) -                        elif temp[x1][y1] > temp[x][y] + 1: -                            temp[x1][y1] = temp[x][y] + 1 -                            dq.append((x1, y1)) -        ans = max(ans, np.max(temp)) +                    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))