def main():

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

    grid = [eval(input()) for _ in [0]*h]

    ans_list = []

    for i in range(h):

        for j in range(w):

            if grid[i][j] == ".":

                ans_list.append((i, j))

    m = 0

    for i, j in ans_list:

        q = [(i, j)]

        dist = [[-1]*w for _ in [0]*h]

        cnt = 0

        dist[i][j] = 0

        while q:

            qq = []

            cnt += 1

            while q:

                x, y = q.pop()

                if x > 0:

                    if dist[x-1][y] == -1:

                        if grid[x-1][y] == ".":

                            dist[x-1][y] = cnt

                            qq.append((x-1, y))

                if x < h-1:

                    if dist[x+1][y] == -1:

                        if grid[x+1][y] == ".":

                            dist[x+1][y] = cnt

                            qq.append((x+1, y))

                if y > 0:

                    if dist[x][y-1] == -1:

                        if grid[x][y-1] == ".":

                            dist[x][y-1] = cnt

                            qq.append((x, y-1))

                if y < w-1:

                    if dist[x][y+1] == -1:

                        if grid[x][y+1] == ".":

                            dist[x][y+1] = cnt

                            qq.append((x, y+1))

            q = qq

        m = max(m, max([max([l for l in k]) for k in dist]))

    print(m)





main()

def main():

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

    grid = ["#"*(w+2)]+["#"+eval(input())+"#" for _ in [0]*h]+["#"*(w+2)]

    #grid = [[i == "." for i in j] for j in grid]

    ans_list = []

    for i in range(1, h+1):

        for j in range(1, w+1):

            if grid[i][j] == ".":

                ans_list.append((i, j))

    m = 0

    for i, j in ans_list:

        q = [(i, j)]

        dist = [[-1]*(w+2) for _ in [0]*(h+2)]

        cnt = 0

        dist[i][j] = 0

        while q:

            qq = []

            cnt += 1

            while q:

                x, y = q.pop()

                if dist[x-1][y] == -1:

                    if grid[x-1][y] == ".":

                        dist[x-1][y] = cnt

                        qq.append((x-1, y))

                if dist[x+1][y] == -1:

                    if grid[x+1][y] == ".":

                        dist[x+1][y] = cnt

                        qq.append((x+1, y))

                if dist[x][y-1] == -1:

                    if grid[x][y-1] == ".":

                        dist[x][y-1] = cnt

                        qq.append((x, y-1))

                if dist[x][y+1] == -1:

                    if grid[x][y+1] == ".":

                        dist[x][y+1] = cnt

                        qq.append((x, y+1))

            q = qq

        m = max(m, max([max([l for l in k]) for k in dist]))

    print(m)





main()
def main():
    h, w = list(map(int, input().split()))
    grid = [eval(input()) for _ in [0] * h]
    ans_list = []
    for i in range(h):
        for j in range(w):
            if grid[i][j] == ".":
                ans_list.append((i, j))
    m = 0
    for i, j in ans_list:
        q = [(i, j)]
        dist = [[-1] * w for _ in [0] * h]
        cnt = 0
        dist[i][j] = 0
        while q:
            qq = []
            cnt += 1
            while q:
                x, y = q.pop()
                if x > 0:
                    if dist[x - 1][y] == -1:
                        if grid[x - 1][y] == ".":
                            dist[x - 1][y] = cnt
                            qq.append((x - 1, y))
                if x < h - 1:
                    if dist[x + 1][y] == -1:
                        if grid[x + 1][y] == ".":
                            dist[x + 1][y] = cnt
                            qq.append((x + 1, y))
                if y > 0:
                    if dist[x][y - 1] == -1:
                        if grid[x][y - 1] == ".":
                            dist[x][y - 1] = cnt
                            qq.append((x, y - 1))
                if y < w - 1:
                    if dist[x][y + 1] == -1:
                        if grid[x][y + 1] == ".":
                            dist[x][y + 1] = cnt
                            qq.append((x, y + 1))
            q = qq
        m = max(m, max([max([l for l in k]) for k in dist]))
    print(m)


main()

def main():
    h, w = list(map(int, input().split()))
    grid = (
        ["#" * (w + 2)] + ["#" + eval(input()) + "#" for _ in [0] * h] + ["#" * (w + 2)]
    )
    # grid = [[i == "." for i in j] for j in grid]
    ans_list = []
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if grid[i][j] == ".":
                ans_list.append((i, j))
    m = 0
    for i, j in ans_list:
        q = [(i, j)]
        dist = [[-1] * (w + 2) for _ in [0] * (h + 2)]
        cnt = 0
        dist[i][j] = 0
        while q:
            qq = []
            cnt += 1
            while q:
                x, y = q.pop()
                if dist[x - 1][y] == -1:
                    if grid[x - 1][y] == ".":
                        dist[x - 1][y] = cnt
                        qq.append((x - 1, y))
                if dist[x + 1][y] == -1:
                    if grid[x + 1][y] == ".":
                        dist[x + 1][y] = cnt
                        qq.append((x + 1, y))
                if dist[x][y - 1] == -1:
                    if grid[x][y - 1] == ".":
                        dist[x][y - 1] = cnt
                        qq.append((x, y - 1))
                if dist[x][y + 1] == -1:
                    if grid[x][y + 1] == ".":
                        dist[x][y + 1] = cnt
                        qq.append((x, y + 1))
            q = qq
        m = max(m, max([max([l for l in k]) for k in dist]))
    print(m)


main()

-    grid = [eval(input()) for _ in [0] * h] +    grid = ( +        ["#" * (w + 2)] + ["#" + eval(input()) + "#" for _ in [0] * h] + ["#" * (w + 2)] +    ) +    # grid = [[i == "." for i in j] for j in grid] -    for i in range(h): -        for j in range(w): +    for i in range(1, h + 1): +        for j in range(1, w + 1): -        dist = [[-1] * w for _ in [0] * h] +        dist = [[-1] * (w + 2) for _ in [0] * (h + 2)] -                if x > 0: -                    if dist[x - 1][y] == -1: -                        if grid[x - 1][y] == ".": -                            dist[x - 1][y] = cnt -                            qq.append((x - 1, y)) -                if x < h - 1: -                    if dist[x + 1][y] == -1: -                        if grid[x + 1][y] == ".": -                            dist[x + 1][y] = cnt -                            qq.append((x + 1, y)) -                if y > 0: -                    if dist[x][y - 1] == -1: -                        if grid[x][y - 1] == ".": -                            dist[x][y - 1] = cnt -                            qq.append((x, y - 1)) -                if y < w - 1: -                    if dist[x][y + 1] == -1: -                        if grid[x][y + 1] == ".": -                            dist[x][y + 1] = cnt -                            qq.append((x, y + 1)) +                if dist[x - 1][y] == -1: +                    if grid[x - 1][y] == ".": +                        dist[x - 1][y] = cnt +                        qq.append((x - 1, y)) +                if dist[x + 1][y] == -1: +                    if grid[x + 1][y] == ".": +                        dist[x + 1][y] = cnt +                        qq.append((x + 1, y)) +                if dist[x][y - 1] == -1: +                    if grid[x][y - 1] == ".": +                        dist[x][y - 1] = cnt +                        qq.append((x, y - 1)) +                if dist[x][y + 1] == -1: +                    if grid[x][y + 1] == ".": +                        dist[x][y + 1] = cnt +                        qq.append((x, y + 1))