from collections import deque

 

def bfs(h, w, s, sx, sy):

    dx = [1, 0, -1, 0]

    dy = [0, 1, 0, -1]

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

    d[sx][sy] = 0

    que = deque()

    que.append((sx, sy))

 

    while que:

        x, y = que.popleft()

        for i in range(4):

            nx = x + dx[i]

            ny = y + dy[i]

            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != '#' and d[nx][ny] == -1:

                que.append((nx, ny))

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

 

    md = 0

    for i in range(h):

        for j in range(w):

          md = max(md, d[i][j])

 

    return md

 

h, w = [int(_) for _ in input().split()]

s = [0] * h

for i in range(h):

    s[i] = list(eval(input()))

 

ans = 0

 

for i in range(h):

    for j in range(w):

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

            ans = max(ans, bfs(h, w, s, i, j))

 

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

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

d = [(1, 0), (-1, 0), (0, 1), (0, -1)]

ans = 0



def bfs(sy, sx):

    if ma[sy][sx] == "#":

        return 0

    q = [[sy, sx, 0]]

    flag = [[0] * w for _ in range(h)]

    flag[sy][sx] = 1

    ans = 0

    while True:

        if len(q) == 0:

            break

        y, x, dist = q.pop(0)

        for dy, dx in d:

            if 0 <= y + dy < h and 0 <= x + dx < w and flag[y + dy][x + dx] == 0 and ma[y + dy][x + dx] == ".":

                flag[y + dy][x + dx] = 1

                q.append([y + dy, x + dx, dist + 1])

                ans = max(ans, dist + 1)



    return ans





for j in range(h):

    for i in range(w):

        ans = max(ans, bfs(j, i))



print(ans)
from collections import deque


def bfs(h, w, s, sx, sy):
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    d = [[-1] * w for _ in range(h)]
    d[sx][sy] = 0
    que = deque()
    que.append((sx, sy))
    while que:
        x, y = que.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and d[nx][ny] == -1:
                que.append((nx, ny))
                d[nx][ny] = d[x][y] + 1
    md = 0
    for i in range(h):
        for j in range(w):
            md = max(md, d[i][j])
    return md


h, w = [int(_) for _ in input().split()]
s = [0] * h
for i in range(h):
    s[i] = list(eval(input()))
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            ans = max(ans, bfs(h, w, s, i, j))
print(ans)

h, w = list(map(int, input().split()))
ma = [list(eval(input())) for _ in range(h)]
d = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans = 0


def bfs(sy, sx):
    if ma[sy][sx] == "#":
        return 0
    q = [[sy, sx, 0]]
    flag = [[0] * w for _ in range(h)]
    flag[sy][sx] = 1
    ans = 0
    while True:
        if len(q) == 0:
            break
        y, x, dist = q.pop(0)
        for dy, dx in d:
            if (
                0 <= y + dy < h
                and 0 <= x + dx < w
                and flag[y + dy][x + dx] == 0
                and ma[y + dy][x + dx] == "."
            ):
                flag[y + dy][x + dx] = 1
                q.append([y + dy, x + dx, dist + 1])
                ans = max(ans, dist + 1)
    return ans


for j in range(h):
    for i in range(w):
        ans = max(ans, bfs(j, i))
print(ans)

-from collections import deque +h, w = list(map(int, input().split())) +ma = [list(eval(input())) for _ in range(h)] +d = [(1, 0), (-1, 0), (0, 1), (0, -1)] +ans = 0 -def bfs(h, w, s, sx, sy): -    dx = [1, 0, -1, 0] -    dy = [0, 1, 0, -1] -    d = [[-1] * w for _ in range(h)] -    d[sx][sy] = 0 -    que = deque() -    que.append((sx, sy)) -    while que: -        x, y = que.popleft() -        for i in range(4): -            nx = x + dx[i] -            ny = y + dy[i] -            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and d[nx][ny] == -1: -                que.append((nx, ny)) -                d[nx][ny] = d[x][y] + 1 -    md = 0 -    for i in range(h): -        for j in range(w): -            md = max(md, d[i][j]) -    return md +def bfs(sy, sx): +    if ma[sy][sx] == "#": +        return 0 +    q = [[sy, sx, 0]] +    flag = [[0] * w for _ in range(h)] +    flag[sy][sx] = 1 +    ans = 0 +    while True: +        if len(q) == 0: +            break +        y, x, dist = q.pop(0) +        for dy, dx in d: +            if ( +                0 <= y + dy < h +                and 0 <= x + dx < w +                and flag[y + dy][x + dx] == 0 +                and ma[y + dy][x + dx] == "." +            ): +                flag[y + dy][x + dx] = 1 +                q.append([y + dy, x + dx, dist + 1]) +                ans = max(ans, dist + 1) +    return ans -h, w = [int(_) for _ in input().split()] -s = [0] * h -for i in range(h): -    s[i] = list(eval(input())) -ans = 0 -for i in range(h): -    for j in range(w): -        if s[i][j] == ".": -            ans = max(ans, bfs(h, w, s, i, j)) +for j in range(h): +    for i in range(w): +        ans = max(ans, bfs(j, i))