H,W = list(map(int,input().split()))

grid = [eval(input()) for i in range(H)]



INF = 10 ** 18



ans = 0

for h in range(H):

    for w in range(W):

        if grid[h][w] == '#':

            continue

        dist = [[INF] * W for _ in range(H)]

        dist[h][w] = 0

        q = [(h,w)]

        d = 1

        while q:

            qq = []

            for y,x in q:

                for dy,dx in [(-1,0),(1,0),(0,-1),(0,1)]:

                    yy,xx = y+dy, x+dx

                    if not (0 <= yy < H and 0 <= xx < W):

                        continue

                    if grid[yy][xx] == '#':

                        continue

                    if dist[yy][xx] != INF:

                        continue

                    dist[yy][xx] = d

                    qq.append((yy,xx))

            q = qq

            d += 1

        for i in range(H):

            for j in range(W):

                if dist[i][j] != INF:

                    ans = max(ans,dist[i][j])



print(ans)
def gridbfs(grid,sy,sx):

    INF = 10**18



    gridy = len(grid)

    gridx = len(grid[0])



    dist = [[INF]*gridx for _ in range(gridy)]

    dist[sy][sx] = 0

    q = [(sy,sx)]

    d = 1



    while q:

        qq = []

        for y,x in q:

            for dy,dx in [(-1,0),(1,0),(0,-1),(0,1)]:

                yy,xx = y+dy, x+dx

                if not (0 <= yy < gridy and 0 <= xx < gridx):

                    continue

                if grid[yy][xx] == '#':

                    continue

                if dist[yy][xx] != INF:

                    continue

                dist[yy][xx] = d

                qq.append((yy,xx))

        q = qq

        d += 1



    return dist



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

s = [eval(input()) for i in range(h)]

c = 0

for i in range(h):

    for j in range(w):

        if s[i][j] == '#':

            continue

        d_list = gridbfs(s,i,j)

        for k in range(h):

            for l in range(w):

                if d_list[k][l] != 10**18:

                    c = max(c,d_list[k][l])

print(c)
H, W = list(map(int, input().split()))
grid = [eval(input()) for i in range(H)]
INF = 10**18
ans = 0
for h in range(H):
    for w in range(W):
        if grid[h][w] == "#":
            continue
        dist = [[INF] * W for _ in range(H)]
        dist[h][w] = 0
        q = [(h, w)]
        d = 1
        while q:
            qq = []
            for y, x in q:
                for dy, dx in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
                    yy, xx = y + dy, x + dx
                    if not (0 <= yy < H and 0 <= xx < W):
                        continue
                    if grid[yy][xx] == "#":
                        continue
                    if dist[yy][xx] != INF:
                        continue
                    dist[yy][xx] = d
                    qq.append((yy, xx))
            q = qq
            d += 1
        for i in range(H):
            for j in range(W):
                if dist[i][j] != INF:
                    ans = max(ans, dist[i][j])
print(ans)

def gridbfs(grid, sy, sx):
    INF = 10**18
    gridy = len(grid)
    gridx = len(grid[0])
    dist = [[INF] * gridx for _ in range(gridy)]
    dist[sy][sx] = 0
    q = [(sy, sx)]
    d = 1
    while q:
        qq = []
        for y, x in q:
            for dy, dx in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
                yy, xx = y + dy, x + dx
                if not (0 <= yy < gridy and 0 <= xx < gridx):
                    continue
                if grid[yy][xx] == "#":
                    continue
                if dist[yy][xx] != INF:
                    continue
                dist[yy][xx] = d
                qq.append((yy, xx))
        q = qq
        d += 1
    return dist


h, w = list(map(int, input().split()))
s = [eval(input()) for i in range(h)]
c = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            continue
        d_list = gridbfs(s, i, j)
        for k in range(h):
            for l in range(w):
                if d_list[k][l] != 10**18:
                    c = max(c, d_list[k][l])
print(c)

-H, W = list(map(int, input().split())) -grid = [eval(input()) for i in range(H)] -INF = 10**18 -ans = 0 -for h in range(H): -    for w in range(W): -        if grid[h][w] == "#": +def gridbfs(grid, sy, sx): +    INF = 10**18 +    gridy = len(grid) +    gridx = len(grid[0]) +    dist = [[INF] * gridx for _ in range(gridy)] +    dist[sy][sx] = 0 +    q = [(sy, sx)] +    d = 1 +    while q: +        qq = [] +        for y, x in q: +            for dy, dx in [(-1, 0), (1, 0), (0, -1), (0, 1)]: +                yy, xx = y + dy, x + dx +                if not (0 <= yy < gridy and 0 <= xx < gridx): +                    continue +                if grid[yy][xx] == "#": +                    continue +                if dist[yy][xx] != INF: +                    continue +                dist[yy][xx] = d +                qq.append((yy, xx)) +        q = qq +        d += 1 +    return dist + + +h, w = list(map(int, input().split())) +s = [eval(input()) for i in range(h)] +c = 0 +for i in range(h): +    for j in range(w): +        if s[i][j] == "#": -        dist = [[INF] * W for _ in range(H)] -        dist[h][w] = 0 -        q = [(h, w)] -        d = 1 -        while q: -            qq = [] -            for y, x in q: -                for dy, dx in [(-1, 0), (1, 0), (0, -1), (0, 1)]: -                    yy, xx = y + dy, x + dx -                    if not (0 <= yy < H and 0 <= xx < W): -                        continue -                    if grid[yy][xx] == "#": -                        continue -                    if dist[yy][xx] != INF: -                        continue -                    dist[yy][xx] = d -                    qq.append((yy, xx)) -            q = qq -            d += 1 -        for i in range(H): -            for j in range(W): -                if dist[i][j] != INF: -                    ans = max(ans, dist[i][j]) -print(ans) +        d_list = gridbfs(s, i, j) +        for k in range(h): +            for l in range(w): +                if d_list[k][l] != 10**18: +                    c = max(c, d_list[k][l]) +print(c)