import queue


class Solution:

    def solve(self, H: int, W: int, S) -> int:
        INF = H*W+1
        dist = {}
        for i in range(H):
            for j in range(W):
                dist[(i, j)] = INF

        def bfs(__start):

            # for i in range(H):
            #     s = ""
            #     for j in range(W):
            #         s += str(dist[(i, j)]) + ","
            #     print(s)
            # print("-----")

            goals = []
            goals.append(__start)
            dist[__start] = 0
            __nexts = queue.Queue()

            __nexts.put(__start)

            while not __nexts.empty():
                __next = __nexts.get()

                __is_node = True

                for delta in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
                    h = __next[0] + delta[0]
                    w = __next[1] + delta[1]
                    if h < 0 or h > H - 1:
                        continue

                    if w < 0 or w > W - 1:
                        continue

                    if S[h][w] != "#" and dist[(h, w)] == INF:
                        __nexts.put((h, w))
                        dist[(h, w)] = dist[__next] + 1
                        __is_node = False

                if __is_node:
                    goals.append(__next)

            return goals

        ans = 0
        for i in range(H):
            for j in range(W):

                # skip if (i,j) is not on the edge
                if 0 < i and i < H - 1 and 0 < j and j < W - 1:
                    continue

                # skip if (i,J) is a wall
                if S[i][j] == "#":
                    continue

                # skip if (i,j) is already visited
                if dist[(i, j)] < INF:
                    continue

                goals = bfs((i, j))

                dists = [dist[goal] for goal in goals]
                dists.sort()

                max_dist = 0
                if len(dists) > 1:
                    max_dist = dists[-1] + dists[-2]

                if ans < max_dist:
                    ans = max_dist

        return ans


if __name__ == '__main__':

    # standard input
    H, W = map(int, input().split())
    S = []
    for h in range(H):
        S.append(input())

    # solve
    solution = Solution()
    print(solution.solve(H, W, S))
