def resolve():

    h, w = list(map(int, input().split()))

    maze = [eval(input()) for _ in range(h)]

    from collections import deque

    def slv(maze, startx, starty):

        if maze[startx][starty] == "#":

            return 0

        else:

            visited = [[-1] * w for _ in range(h)]

            visited[startx][starty] = 0

            nxt = deque([[startx, starty]])

            while len(nxt) != 0:

                a = nxt.popleft()

                x = a[0]

                y = a[1]

                if 0 <= (x + 1) < h and 0 <= y < w:

                    if maze[x + 1][y] == "." and visited[x + 1][y] == -1:

                        visited[x + 1][y] = visited[x][y] + 1

                        nxt.append([x + 1, y])

                if 0 <= x < h and 0 <= y - 1 < w:

                    if maze[x][y - 1] == "." and visited[x][y - 1] == -1:

                        visited[x][y - 1] = visited[x][y] + 1

                        nxt.append([x, y - 1])

                if 0 <= x - 1 < h and 0 <= y < w:

                    if maze[x - 1][y] == "." and visited[x - 1][y] == -1:

                        visited[x - 1][y] = visited[x][y] + 1

                        nxt.append([x - 1, y])

                if 0 <= x < h and 0 <= y + 1 < w:

                    if maze[x][y + 1] == "." and visited[x][y + 1] == -1:

                        visited[x][y + 1] = visited[x][y] + 1

                        nxt.append([x, y + 1])

            rtn = 0

            for i in range(h):

                rtn = max(rtn, max(visited[i]))

            return rtn



    ans = 0

    for i in range(h):

        for j in range(w):

            ans = max(slv(maze, i, j), ans)

    print(ans)

resolve()
def resolve():

    h, w = list(map(int, input().split()))

    maze = [eval(input()) for _ in range(h)]

    from collections import deque

    def slv(maze, startx, starty):

        if maze[startx][starty] == "#":

            return 0

        else:

            visited = [[-1] * w for _ in range(h)]

            visited[startx][starty] = 0

            nxt = deque([[startx, starty]])

            while len(nxt) != 0:

                a = nxt.popleft()

                x = a[0]

                y = a[1]

                for i, j in [(x+1, y), (x, y+1), (x-1, y), (x, y-1)]:

                    if 0 <= i < h and 0 <= j < w:

                        if maze[i][j] == "." and visited[i][j] == -1:

                            visited[i][j] = visited[x][y] + 1

                            nxt.append([i,j])

            rtn = 0

            for i in range(h):

                rtn = max(rtn, max(visited[i]))

            return rtn



    ans = 0

    for i in range(h):

        for j in range(w):

            ans = max(slv(maze, i, j), ans)

    print(ans)

resolve()
def resolve():
    h, w = list(map(int, input().split()))
    maze = [eval(input()) for _ in range(h)]
    from collections import deque

    def slv(maze, startx, starty):
        if maze[startx][starty] == "#":
            return 0
        else:
            visited = [[-1] * w for _ in range(h)]
            visited[startx][starty] = 0
            nxt = deque([[startx, starty]])
            while len(nxt) != 0:
                a = nxt.popleft()
                x = a[0]
                y = a[1]
                if 0 <= (x + 1) < h and 0 <= y < w:
                    if maze[x + 1][y] == "." and visited[x + 1][y] == -1:
                        visited[x + 1][y] = visited[x][y] + 1
                        nxt.append([x + 1, y])
                if 0 <= x < h and 0 <= y - 1 < w:
                    if maze[x][y - 1] == "." and visited[x][y - 1] == -1:
                        visited[x][y - 1] = visited[x][y] + 1
                        nxt.append([x, y - 1])
                if 0 <= x - 1 < h and 0 <= y < w:
                    if maze[x - 1][y] == "." and visited[x - 1][y] == -1:
                        visited[x - 1][y] = visited[x][y] + 1
                        nxt.append([x - 1, y])
                if 0 <= x < h and 0 <= y + 1 < w:
                    if maze[x][y + 1] == "." and visited[x][y + 1] == -1:
                        visited[x][y + 1] = visited[x][y] + 1
                        nxt.append([x, y + 1])
            rtn = 0
            for i in range(h):
                rtn = max(rtn, max(visited[i]))
            return rtn

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(slv(maze, i, j), ans)
    print(ans)


resolve()

def resolve():
    h, w = list(map(int, input().split()))
    maze = [eval(input()) for _ in range(h)]
    from collections import deque

    def slv(maze, startx, starty):
        if maze[startx][starty] == "#":
            return 0
        else:
            visited = [[-1] * w for _ in range(h)]
            visited[startx][starty] = 0
            nxt = deque([[startx, starty]])
            while len(nxt) != 0:
                a = nxt.popleft()
                x = a[0]
                y = a[1]
                for i, j in [(x + 1, y), (x, y + 1), (x - 1, y), (x, y - 1)]:
                    if 0 <= i < h and 0 <= j < w:
                        if maze[i][j] == "." and visited[i][j] == -1:
                            visited[i][j] = visited[x][y] + 1
                            nxt.append([i, j])
            rtn = 0
            for i in range(h):
                rtn = max(rtn, max(visited[i]))
            return rtn

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(slv(maze, i, j), ans)
    print(ans)


resolve()

-                if 0 <= (x + 1) < h and 0 <= y < w: -                    if maze[x + 1][y] == "." and visited[x + 1][y] == -1: -                        visited[x + 1][y] = visited[x][y] + 1 -                        nxt.append([x + 1, y]) -                if 0 <= x < h and 0 <= y - 1 < w: -                    if maze[x][y - 1] == "." and visited[x][y - 1] == -1: -                        visited[x][y - 1] = visited[x][y] + 1 -                        nxt.append([x, y - 1]) -                if 0 <= x - 1 < h and 0 <= y < w: -                    if maze[x - 1][y] == "." and visited[x - 1][y] == -1: -                        visited[x - 1][y] = visited[x][y] + 1 -                        nxt.append([x - 1, y]) -                if 0 <= x < h and 0 <= y + 1 < w: -                    if maze[x][y + 1] == "." and visited[x][y + 1] == -1: -                        visited[x][y + 1] = visited[x][y] + 1 -                        nxt.append([x, y + 1]) +                for i, j in [(x + 1, y), (x, y + 1), (x - 1, y), (x, y - 1)]: +                    if 0 <= i < h and 0 <= j < w: +                        if maze[i][j] == "." and visited[i][j] == -1: +                            visited[i][j] = visited[x][y] + 1 +                            nxt.append([i, j])