import queue

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

h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]

ans = 0

#startを順に探索
for y in range(h):
    for x in range(w):
    
        i = 0
        move = [[-1] * w for _ in range(h)]
        print(x, y)
        #壁はスキップ
        if(maze[y][x] == '#'):
            continue

        #幅優先探索
        q = queue.Queue()
        q.put([x, y])
        move[y][x] = 0

        while not q.empty():
            pos = q.get()
            for i in range(4):
                next = [pos[0] + dx[i], pos[1] + dy[i]]

                #端
                if(next[0] == w or next[1] == h or next[0] < 0 or next[1] < 0):
                    continue

                if(maze[next[1]][next[0]] == '.' and move[next[1]][next[0]] == -1):
                    move[next[1]][next[0]] = move[pos[1]][pos[0]] + 1
                    q.put(next)
        ans = max([ans] + [max(v) for v in move])

print(ans)

