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 0<= x < H and 0<= y < W and 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



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)]

def BFS(i,j):

    q = deque()

    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

                if 0<= x < H and 0<= y < W and 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))

        return Ma

    return 0

for i in range(H):#全部の地点でBFSをためす

    for j in range(W):

        Max_list.append(BFS(i,j))



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 (
                        0 <= x < H
                        and 0 <= y < W
                        and 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

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)]


def BFS(i, j):
    q = deque()
    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
                if 0 <= x < H and 0 <= y < W and 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))
        return Ma
    return 0


for i in range(H):  # 全部の地点でBFSをためす
    for j in range(W):
        Max_list.append(BFS(i, j))
print((max(Max_list)))

-""" -INF = float('inf') -MOD = 10 ** 9 + 7 -""" -## ここは１つにまとめれる -# dy = (0, -1, 0, 1) -# dx = (1, 0, -1, 0) -q = deque() -for i in range(H): + + +def BFS(i, j): +    q = deque() +    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 +                if 0 <= x < H and 0 <= y < W and 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)) +        return Ma +    return 0 + + +for i in range(H):  # 全部の地点でBFSをためす -        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 ( -                        0 <= x < H -                        and 0 <= y < W -                        and 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) +        Max_list.append(BFS(i, j))