def resolve():
    H, W = map(int, input().split())
    s = [input() for _ in range(H)]

    def bfs(row, col, R, C, goal_r, goal_c, s):
        if s[goal_r][goal_c] == '#':
            return -1

        from collections import deque
        q = deque()
        q.append([(row, col), 0])
        seen = set()
        ans = -1
        while q:
            (r, c), dist = q.popleft()
            seen.add((r, c))
            if r == goal_r and c == goal_c:
                ans = dist
                break
            for (next_r, next_c) in ((r+1, c), (r-1, c), (r, c+1), (r, c-1)):
                if 0 <= next_r < R and 0 <= next_c < C and \
                   (next_r, next_c) not in seen and \
                   s[next_r][next_c] == '.':
                    q.append([(next_r, next_c), dist + 1])
        return ans

    def helper(i, j, row, column, s):
        max_v = -1
        for r in range(row):
            for c in range(column):
                max_v = max(max_v, bfs(i, j, H, W, r, c, s))
        return max_v

    max_v = -1
    for h in range(H):
        for w in range(W):
            max_v = max(max_v, helper(h, w, H, W, s))
    print(max_v)
resolve()