# 上下左右どこでもいける

# BFS

from queue import Queue

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

MAZE = ['#'*(w+2)]

for _ in range(h):

    MAZE.append("#"+eval(input())+"#")

else:

    MAZE.append('#'*(w+2))



INF = 10**3

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





def bfs(init_x, init_y):

    dp = [[INF]*(w+2) for _ in range(h+2)]

    resisterd = [[0]*(w+2) for _ in range(h+2)]

    q = Queue()

    q.put((init_x, init_y))

    dp[init_x][init_y] = 0

    MAX = 0

    while not q.empty():

        x, y = q.get()

        for i, j in directions:

            if MAZE[x+i][y+j] == '#':

                continue

            if resisterd[x+i][y+j]:

                continue

            resisterd[x+i][y+j] = 1

            q.put((x+i, y+j))

        dp[x][y] = min(dp[x][y], min(dp[x+v][y+w]+1 for v, w in directions))

        MAX = max(MAX, dp[x][y])

    return MAX





ans = 0

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

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

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

            continue

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

print(ans)
from queue import Queue

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

MAZE = ['#'*(w+2)]

for _ in range(h):

    MAZE.append("#"+eval(input())+"#")

else:

    MAZE.append('#'*(w+2))



INF = 10**3

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





def bfs(init_x, init_y):

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

    q = Queue()

    q.put((init_x, init_y))

    dist[init_x][init_y] = 0

    MAX = 0

    while not q.empty():

        x, y = q.get()

        for i, j in directions:

            if MAZE[x+i][y+j] == '#':

                continue

            if dist[x+i][y+j] <= dist[x][y]+1:

                continue

            dist[x+i][y+j] = dist[x][y]+1

            q.put((x+i, y+j))

        MAX = max(MAX, dist[x][y])

    return MAX





ans = 0

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

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

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

            continue

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

print(ans)

# 上下左右どこでもいける
# BFS
from queue import Queue

h, w = list(map(int, input().split()))
MAZE = ["#" * (w + 2)]
for _ in range(h):
    MAZE.append("#" + eval(input()) + "#")
else:
    MAZE.append("#" * (w + 2))
INF = 10**3
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]


def bfs(init_x, init_y):
    dp = [[INF] * (w + 2) for _ in range(h + 2)]
    resisterd = [[0] * (w + 2) for _ in range(h + 2)]
    q = Queue()
    q.put((init_x, init_y))
    dp[init_x][init_y] = 0
    MAX = 0
    while not q.empty():
        x, y = q.get()
        for i, j in directions:
            if MAZE[x + i][y + j] == "#":
                continue
            if resisterd[x + i][y + j]:
                continue
            resisterd[x + i][y + j] = 1
            q.put((x + i, y + j))
        dp[x][y] = min(dp[x][y], min(dp[x + v][y + w] + 1 for v, w in directions))
        MAX = max(MAX, dp[x][y])
    return MAX


ans = 0
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if MAZE[i][j] == "#":
            continue
        ans = max(ans, bfs(i, j))
print(ans)

from queue import Queue

h, w = list(map(int, input().split()))
MAZE = ["#" * (w + 2)]
for _ in range(h):
    MAZE.append("#" + eval(input()) + "#")
else:
    MAZE.append("#" * (w + 2))
INF = 10**3
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]


def bfs(init_x, init_y):
    dist = [[INF] * (w + 2) for _ in range(h + 2)]
    q = Queue()
    q.put((init_x, init_y))
    dist[init_x][init_y] = 0
    MAX = 0
    while not q.empty():
        x, y = q.get()
        for i, j in directions:
            if MAZE[x + i][y + j] == "#":
                continue
            if dist[x + i][y + j] <= dist[x][y] + 1:
                continue
            dist[x + i][y + j] = dist[x][y] + 1
            q.put((x + i, y + j))
        MAX = max(MAX, dist[x][y])
    return MAX


ans = 0
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if MAZE[i][j] == "#":
            continue
        ans = max(ans, bfs(i, j))
print(ans)

-# 上下左右どこでもいける -# BFS -    dp = [[INF] * (w + 2) for _ in range(h + 2)] -    resisterd = [[0] * (w + 2) for _ in range(h + 2)] +    dist = [[INF] * (w + 2) for _ in range(h + 2)] -    dp[init_x][init_y] = 0 +    dist[init_x][init_y] = 0 -            if resisterd[x + i][y + j]: +            if dist[x + i][y + j] <= dist[x][y] + 1: -            resisterd[x + i][y + j] = 1 +            dist[x + i][y + j] = dist[x][y] + 1 -        dp[x][y] = min(dp[x][y], min(dp[x + v][y + w] + 1 for v, w in directions)) -        MAX = max(MAX, dp[x][y]) +        MAX = max(MAX, dist[x][y])