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



def cl(sx, sy, m):

    Z = -1

    dist = [[Z for i in range(w)] for j in range(h)]

    for i in range(h):

        for j in range(w):

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

                dist[i][j] = -1



    def bfs():

        q = []

        q.insert(0, (sx, sy))

        dist[sy][sx] = 0

        while len(q):

            x, y = q.pop()

            for i in range(0, 4):

                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]

                if (0 <= nx < w and 0 <= ny < h and m[ny][nx] != '#' and dist[ny][nx] == Z):

                    q.insert(0, (nx, ny))

                    dist[ny][nx] = dist[y][x] + 1

        return dist

    return bfs()



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

ans = 0

for y in range(h):

    for x in range(w):

        e = S[y][x]

        if e != '#':

            num = cl(x, y, S)

            for k in range(h):

                ans = max(ans, max(num[k]))

print(ans)

from collections import deque

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

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

INF = 10010001001

way = [[0, 1], [0, -1], [1, 0], [-1, 0]]



ans = 0

for sy in range(h):

    for sx in range(w):

        dist = [[INF] * w for _ in range(h)]

        dist[sy][sx] = 0

        if S[sy][sx] == '#':

            continue

        q = deque()

        q.append((sy, sx))

        while len(q):

            y, x = q.popleft()

            for dy, dx in way:

                ny, nx = y + dy, x + dx

                if not (0 <= ny <= h - 1 and 0 <= nx <= w - 1):

                    continue

                if S[ny][nx] == '#' or dist[ny][nx] != INF:

                    continue

                dist[ny][nx] = dist[y][x] + 1

                q.append((ny, nx))

        for yy in range(h):

            for xx in range(w):

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

                    continue

                else:

                    ans = max(ans, dist[yy][xx])

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


def cl(sx, sy, m):
    Z = -1
    dist = [[Z for i in range(w)] for j in range(h)]
    for i in range(h):
        for j in range(w):
            if m[i][j] == "#":
                dist[i][j] = -1

    def bfs():
        q = []
        q.insert(0, (sx, sy))
        dist[sy][sx] = 0
        while len(q):
            x, y = q.pop()
            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
                if (
                    0 <= nx < w
                    and 0 <= ny < h
                    and m[ny][nx] != "#"
                    and dist[ny][nx] == Z
                ):
                    q.insert(0, (nx, ny))
                    dist[ny][nx] = dist[y][x] + 1
        return dist

    return bfs()


S = [list(eval(input())) for _ in range(h)]
ans = 0
for y in range(h):
    for x in range(w):
        e = S[y][x]
        if e != "#":
            num = cl(x, y, S)
            for k in range(h):
                ans = max(ans, max(num[k]))
print(ans)

from collections import deque

h, w = list(map(int, input().split()))
S = [list(eval(input())) for _ in range(h)]
INF = 10010001001
way = [[0, 1], [0, -1], [1, 0], [-1, 0]]
ans = 0
for sy in range(h):
    for sx in range(w):
        dist = [[INF] * w for _ in range(h)]
        dist[sy][sx] = 0
        if S[sy][sx] == "#":
            continue
        q = deque()
        q.append((sy, sx))
        while len(q):
            y, x = q.popleft()
            for dy, dx in way:
                ny, nx = y + dy, x + dx
                if not (0 <= ny <= h - 1 and 0 <= nx <= w - 1):
                    continue
                if S[ny][nx] == "#" or dist[ny][nx] != INF:
                    continue
                dist[ny][nx] = dist[y][x] + 1
                q.append((ny, nx))
        for yy in range(h):
            for xx in range(w):
                if dist[yy][xx] == INF:
                    continue
                else:
                    ans = max(ans, dist[yy][xx])
print(ans)

+from collections import deque + - - -def cl(sx, sy, m): -    Z = -1 -    dist = [[Z for i in range(w)] for j in range(h)] -    for i in range(h): -        for j in range(w): -            if m[i][j] == "#": -                dist[i][j] = -1 - -    def bfs(): -        q = [] -        q.insert(0, (sx, sy)) +S = [list(eval(input())) for _ in range(h)] +INF = 10010001001 +way = [[0, 1], [0, -1], [1, 0], [-1, 0]] +ans = 0 +for sy in range(h): +    for sx in range(w): +        dist = [[INF] * w for _ in range(h)] +        if S[sy][sx] == "#": +            continue +        q = deque() +        q.append((sy, sx)) -            x, y = q.pop() -            for i in range(0, 4): -                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i] -                if ( -                    0 <= nx < w -                    and 0 <= ny < h -                    and m[ny][nx] != "#" -                    and dist[ny][nx] == Z -                ): -                    q.insert(0, (nx, ny)) -                    dist[ny][nx] = dist[y][x] + 1 -        return dist - -    return bfs() - - -S = [list(eval(input())) for _ in range(h)] -ans = 0 -for y in range(h): -    for x in range(w): -        e = S[y][x] -        if e != "#": -            num = cl(x, y, S) -            for k in range(h): -                ans = max(ans, max(num[k])) +            y, x = q.popleft() +            for dy, dx in way: +                ny, nx = y + dy, x + dx +                if not (0 <= ny <= h - 1 and 0 <= nx <= w - 1): +                    continue +                if S[ny][nx] == "#" or dist[ny][nx] != INF: +                    continue +                dist[ny][nx] = dist[y][x] + 1 +                q.append((ny, nx)) +        for yy in range(h): +            for xx in range(w): +                if dist[yy][xx] == INF: +                    continue +                else: +                    ans = max(ans, dist[yy][xx])