from collections import deque

 

INF = float('inf')

MOD = 10 ** 9 + 7

dy = (0, -1, 0, 1)

dx = (1, 0, -1, 0)





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

M = []

Max_list = []

for i  in range(H):

    t = eval(input())

    M.append(t)

dx = [0,0,-1,1]

dy = [1,-1,0,0]

dist = [[-1]*W for _ in range(H)]

q = deque()

for i in range(H):

    for j in range(W):

        dist = [[-1]*W for _ in range(H)]

        if M[i][j] == '.':

            Ma = 0

            q.append((i, j))

            dist[i][j] = 0

            while q:

                cx,cy = q.popleft()

                for nx,ny in zip(dx,dy):

                    x ,y= cx+nx,cy+ny

                    if x<0 or y<0 or x>=H or y>=W or dist[x][y]>0:

                        continue

                    if M[x][y] == "." and dist[x][y] == -1:

                        dist[x][y]=dist[cx][cy]+1

                        Ma = max(Ma,dist[x][y])

                        q.append((x,y))

            # print(Ma)

            Max_list.append(Ma)

# print(Max_list)



print((max(Max_list)))
from collections import deque

''' 

INF = float('inf')

MOD = 10 ** 9 + 7

'''

## ここは１つにまとめれる

# dy = (0, -1, 0, 1)

# dx = (1, 0, -1, 0)

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



    

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

M = []

Max_list = []

for i  in range(H):

    t = eval(input())

    M.append(t)

dist = [[-1]*W for _ in range(H)]

q = deque()

for i in range(H):

    for j in range(W):

        dist = [[-1]*W for _ in range(H)]

        if M[i][j] == '.':

            Ma = 0

            q.append((i, j))

            dist[i][j] = 0

            while q:

                cx,cy = q.popleft()

                for nx,ny in d:

                    x ,y= cx+nx,cy+ny

                    ''' ここの処理がをnotにしてわかりやすく

                    if x<0 or y<0 or x>=H or y>=W or dist[x][y]>0:

                        continue

                    '''

                    if 0<= x < H and 0<= y < W and dist[x][y]<=0:



                        if M[x][y] == "." and dist[x][y] == -1:

                            dist[x][y]=dist[cx][cy]+1

                            Ma = max(Ma,dist[x][y])

                            q.append((x,y))

            Max_list.append(Ma)



print((max(Max_list)))
from collections import deque

INF = float("inf")
MOD = 10**9 + 7
dy = (0, -1, 0, 1)
dx = (1, 0, -1, 0)
H, W = list(map(int, input().split()))
M = []
Max_list = []
for i in range(H):
    t = eval(input())
    M.append(t)
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]
dist = [[-1] * W for _ in range(H)]
q = deque()
for i in range(H):
    for j in range(W):
        dist = [[-1] * W for _ in range(H)]
        if M[i][j] == ".":
            Ma = 0
            q.append((i, j))
            dist[i][j] = 0
            while q:
                cx, cy = q.popleft()
                for nx, ny in zip(dx, dy):
                    x, y = cx + nx, cy + ny
                    if x < 0 or y < 0 or x >= H or y >= W or dist[x][y] > 0:
                        continue
                    if M[x][y] == "." and dist[x][y] == -1:
                        dist[x][y] = dist[cx][cy] + 1
                        Ma = max(Ma, dist[x][y])
                        q.append((x, y))
            # print(Ma)
            Max_list.append(Ma)
# print(Max_list)
print((max(Max_list)))

from collections import deque

""" 
INF = float('inf')
MOD = 10 ** 9 + 7
"""
## ここは１つにまとめれる
# dy = (0, -1, 0, 1)
# dx = (1, 0, -1, 0)
d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
H, W = list(map(int, input().split()))
M = []
Max_list = []
for i in range(H):
    t = eval(input())
    M.append(t)
dist = [[-1] * W for _ in range(H)]
q = deque()
for i in range(H):
    for j in range(W):
        dist = [[-1] * W for _ in range(H)]
        if M[i][j] == ".":
            Ma = 0
            q.append((i, j))
            dist[i][j] = 0
            while q:
                cx, cy = q.popleft()
                for nx, ny in d:
                    x, y = cx + nx, cy + ny
                    """ ここの処理がをnotにしてわかりやすく
                    if x<0 or y<0 or x>=H or y>=W or dist[x][y]>0:
                        continue
                    """
                    if 0 <= x < H and 0 <= y < W and dist[x][y] <= 0:
                        if M[x][y] == "." and dist[x][y] == -1:
                            dist[x][y] = dist[cx][cy] + 1
                            Ma = max(Ma, dist[x][y])
                            q.append((x, y))
            Max_list.append(Ma)
print((max(Max_list)))

-INF = float("inf") -MOD = 10**9 + 7 -dy = (0, -1, 0, 1) -dx = (1, 0, -1, 0) +""" +INF = float('inf') +MOD = 10 ** 9 + 7 +""" +## ここは１つにまとめれる +# dy = (0, -1, 0, 1) +# dx = (1, 0, -1, 0) +d = [(1, 0), (0, 1), (-1, 0), (0, -1)] -dx = [0, 0, -1, 1] -dy = [1, -1, 0, 0] -                for nx, ny in zip(dx, dy): +                for nx, ny in d: -                    if x < 0 or y < 0 or x >= H or y >= W or dist[x][y] > 0: +                    """ ここの処理がをnotにしてわかりやすく +                    if x<0 or y<0 or x>=H or y>=W or dist[x][y]>0: -                    if M[x][y] == "." and dist[x][y] == -1: -                        dist[x][y] = dist[cx][cy] + 1 -                        Ma = max(Ma, dist[x][y]) -                        q.append((x, y)) -            # print(Ma) +                    """ +                    if 0 <= x < H and 0 <= y < W and dist[x][y] <= 0: +                        if M[x][y] == "." and dist[x][y] == -1: +                            dist[x][y] = dist[cx][cy] + 1 +                            Ma = max(Ma, dist[x][y]) +                            q.append((x, y)) -# print(Max_list)