from collections import deque

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

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

def bfs(si, sj):

    que = deque()

    que.append((si, sj))

    d = [[float('inf')] * w for i in range(h)]

    d[si][sj] = 0

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

    while que:

        i, j = que.popleft()

        for mi, mj in move:

            ni, nj = i + mi, j + mj

            if 0 <= ni < h and 0 <= nj < w and square[ni][nj] != '#' and d[ni][nj] == float('inf'):

                que.append((ni, nj))

                d[ni][nj] = d[i][j] + 1

    return d[i][j]



max_num = 0

for i in range(h):

    for j in range(w):

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

            max_ij = bfs(i, j)

            max_num = max(max_num, max_ij)

print(max_num)
from collections import deque

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

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

def bfs(si, sj):

    INF = 100

    que = deque([(si, sj)])

    d = [[INF] * w for i in range(h)]

    d[si][sj] = 0

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

    while que:

        i, j = que.popleft()

        for mi, mj in move:

            ni, nj = i + mi, j + mj

            if 0 <= ni < h and 0 <= nj < w and square[ni][nj] == '.' and d[ni][nj] == INF:

                que.append((ni, nj))

                d[ni][nj] = d[i][j] + 1

    return d[i][j]



max_num = 0

for i in range(h):

    for j in range(w):

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

            max_ij = bfs(i, j)

            max_num = max(max_num, max_ij)

print(max_num)
from collections import deque

h, w = list(map(int, input().split()))
square = [list(eval(input())) for i in range(h)]


def bfs(si, sj):
    que = deque()
    que.append((si, sj))
    d = [[float("inf")] * w for i in range(h)]
    d[si][sj] = 0
    move = [(-1, 0), (0, 1), (1, 0), (0, -1)]
    while que:
        i, j = que.popleft()
        for mi, mj in move:
            ni, nj = i + mi, j + mj
            if (
                0 <= ni < h
                and 0 <= nj < w
                and square[ni][nj] != "#"
                and d[ni][nj] == float("inf")
            ):
                que.append((ni, nj))
                d[ni][nj] = d[i][j] + 1
    return d[i][j]


max_num = 0
for i in range(h):
    for j in range(w):
        if square[i][j] == ".":
            max_ij = bfs(i, j)
            max_num = max(max_num, max_ij)
print(max_num)

from collections import deque

h, w = list(map(int, input().split()))
square = [list(eval(input())) for i in range(h)]


def bfs(si, sj):
    INF = 100
    que = deque([(si, sj)])
    d = [[INF] * w for i in range(h)]
    d[si][sj] = 0
    move = [(-1, 0), (0, 1), (1, 0), (0, -1)]
    while que:
        i, j = que.popleft()
        for mi, mj in move:
            ni, nj = i + mi, j + mj
            if (
                0 <= ni < h
                and 0 <= nj < w
                and square[ni][nj] == "."
                and d[ni][nj] == INF
            ):
                que.append((ni, nj))
                d[ni][nj] = d[i][j] + 1
    return d[i][j]


max_num = 0
for i in range(h):
    for j in range(w):
        if square[i][j] == ".":
            max_ij = bfs(i, j)
            max_num = max(max_num, max_ij)
print(max_num)

-    que = deque() -    que.append((si, sj)) -    d = [[float("inf")] * w for i in range(h)] +    INF = 100 +    que = deque([(si, sj)]) +    d = [[INF] * w for i in range(h)] -                and square[ni][nj] != "#" -                and d[ni][nj] == float("inf") +                and square[ni][nj] == "." +                and d[ni][nj] == INF