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

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

    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]==-1:
            maze[h][w]=0
            while min(min(maze))==-1:
                for hi in range(H):
                    for wi in range(W):
                        if maze[hi][wi]==-1:
                            e_list=[]
                            if hi>0:
                                a=maze[hi-1][wi]
                                if a!=-1 and a!=999:
                                    e_list.append(a)

                            if hi<H-1:
                                a=maze[hi+1][wi]
                                if a!=-1 and a!=999:
                                    e_list.append(a)

                            if wi>0:
                                a=maze[hi][wi-1]
                                if a!=-1 and a!=999:
                                    e_list.append(a)

                            if wi<W-1:
                                a=maze[hi][wi+1]
                                if a!=-1 and a!=999:
                                    e_list.append(a)

                            if len(e_list) >0:
                                maze[hi][wi]=min(e_list)+1
        

            for hi in range(H):
                for wi in range(W):
                    if maze[hi][wi]!=999:
                        maxd=max(maxd,maze[hi][wi])
        
print(maxd)