import queue
height,width=map(int,input().split())

graph=[]
for _ in range(height):
    s_row = input()
    row = []
    for s in s_row:
        row.append(s)
    graph.append(row)

diff=[[0,-1],[0,1],[-1,0],[1,0]]
max_step=[]
for h in range(height):
    for w in range(width):
        if graph[h][w]=='#':
            continue

        route = []
        for _ in range(height):
            route.append([-1]*width)

        # start x,y,経路数
        q = queue.Queue()
        q.put([w,h,0])

        while not q.empty():
            now = q.get()

            route[now[1]][now[0]] = now[2]

            for dx,dy in diff:
                next_w = now[0]+dx
                next_h = now[1]+dy
                if   width<=next_w \
                  or height<=next_h \
                  or next_w < 0 \
                  or next_h < 0 \
                  or graph[next_h][next_w]=='#' \
                  or route[next_h][next_w]>-1:
                    continue
                q.put([next_w, next_h, now[2]+1])
        
        max_step.append(max(max(step) for step in route))
        
print(max(max_step))