import copy

def agent(maze,ori):
    global H
    global W

    hi=ori[0]
    wi=ori[1]
    root=[]
    if hi > 0:
        root.append([hi-1,wi])
    if hi < H-1:
        root.append([hi+1,wi])
    if wi > 0:
        root.append([hi,wi-1])
    if wi < W-1:
        root.append([hi,wi+1])
    
    for h,w in root:
        if maze[h][w]==".":
            maze[h][w]=maze[hi][wi]+1
            agent(maze,[h,w])
        elif maze[h][w]=="#":
            pass
        else:
            if maze[h][w] > maze[hi][wi]+1:
                maze[h][w]=maze[hi][wi]+1
                agent(maze,[h,w])


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

maze=[]
for h in range(H):
    maze_w=list(input())
    lis=[]
    for e in maze_w:
        if e =="#":
            lis.append(-1)
        else:
            lis.append(e)

    maze.append(lis)

maze_ori=copy.deepcopy(maze)
maxd=0

for h in range(H):
    for w  in range(W):
        maze=copy.deepcopy(maze_ori)
        if maze[h][w]==".":
            maze[h][w]=0
            agent(maze,[h,w])
            maxd=max(maxd,max(max(maze)))
            print(maze)
        else:
            pass


print(maxd)
