from collections import *

from copy import *

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

S = [(W+2)*["#"]]+[["#"]+list(eval(input()))+["#"] for h in range(H)]+[(W+2)*["#"]]

D = [[1,0],[-1,0],[0,1],[0,-1]]

ans = 0

P = deque([])

Q = deque([])

 

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

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

    if S[h][w]==".":

      P+=[[h,w]]

 

while P:

  T = deepcopy(S)

  sx,sy = P.popleft()

  T[sx][sy] = 0

  Q = deque([[sx,sy]])

  while Q:

    x,y = Q.popleft()

    for dx,dy in D:

      if T[x+dx][y+dy]==".":

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

        Q+=[[x+dx,y+dy]]

        ans = max(ans,T[x+dx][y+dy])

 

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

s = [list(eval(input())) for j in range(H)]



def bfs(h, w):

    checked = [[False for i in range(W)] for j in range(H)]

    q = [(h, w, 0)] if s[h][w] == '.' else []

    checked[h][w] = True

    g_n = 0

    while q:

        h_, w_, n = q.pop(0)

        g_n = max(n, g_n)

        for i, j in zip([0,0,-1,1],[-1,1,0,0]):

            if (0 <= h_+i < H) and (0 <= w_+j < W):

                if checked[h_+i][w_+j]: continue

                checked[h_+i][w_+j] = True

                if s[h_+i][w_+j] == '.': q.append((h_+i, w_+j, n+1))

    return g_n



n = 0

for i in range(H):

    for j in range(W):

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



print(n)
from collections import *
from copy import *

H, W = list(map(int, input().split()))
S = (
    [(W + 2) * ["#"]]
    + [["#"] + list(eval(input())) + ["#"] for h in range(H)]
    + [(W + 2) * ["#"]]
)
D = [[1, 0], [-1, 0], [0, 1], [0, -1]]
ans = 0
P = deque([])
Q = deque([])
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if S[h][w] == ".":
            P += [[h, w]]
while P:
    T = deepcopy(S)
    sx, sy = P.popleft()
    T[sx][sy] = 0
    Q = deque([[sx, sy]])
    while Q:
        x, y = Q.popleft()
        for dx, dy in D:
            if T[x + dx][y + dy] == ".":
                T[x + dx][y + dy] = T[x][y] + 1
                Q += [[x + dx, y + dy]]
                ans = max(ans, T[x + dx][y + dy])
print(ans)

H, W = list(map(int, input().split()))
s = [list(eval(input())) for j in range(H)]


def bfs(h, w):
    checked = [[False for i in range(W)] for j in range(H)]
    q = [(h, w, 0)] if s[h][w] == "." else []
    checked[h][w] = True
    g_n = 0
    while q:
        h_, w_, n = q.pop(0)
        g_n = max(n, g_n)
        for i, j in zip([0, 0, -1, 1], [-1, 1, 0, 0]):
            if (0 <= h_ + i < H) and (0 <= w_ + j < W):
                if checked[h_ + i][w_ + j]:
                    continue
                checked[h_ + i][w_ + j] = True
                if s[h_ + i][w_ + j] == ".":
                    q.append((h_ + i, w_ + j, n + 1))
    return g_n


n = 0
for i in range(H):
    for j in range(W):
        n = max(n, bfs(i, j))
print(n)

-from collections import * -from copy import * +H, W = list(map(int, input().split())) +s = [list(eval(input())) for j in range(H)] -H, W = list(map(int, input().split())) -S = ( -    [(W + 2) * ["#"]] -    + [["#"] + list(eval(input())) + ["#"] for h in range(H)] -    + [(W + 2) * ["#"]] -) -D = [[1, 0], [-1, 0], [0, 1], [0, -1]] -ans = 0 -P = deque([]) -Q = deque([]) -for h in range(1, H + 1): -    for w in range(1, W + 1): -        if S[h][w] == ".": -            P += [[h, w]] -while P: -    T = deepcopy(S) -    sx, sy = P.popleft() -    T[sx][sy] = 0 -    Q = deque([[sx, sy]]) -    while Q: -        x, y = Q.popleft() -        for dx, dy in D: -            if T[x + dx][y + dy] == ".": -                T[x + dx][y + dy] = T[x][y] + 1 -                Q += [[x + dx, y + dy]] -                ans = max(ans, T[x + dx][y + dy]) -print(ans) + +def bfs(h, w): +    checked = [[False for i in range(W)] for j in range(H)] +    q = [(h, w, 0)] if s[h][w] == "." else [] +    checked[h][w] = True +    g_n = 0 +    while q: +        h_, w_, n = q.pop(0) +        g_n = max(n, g_n) +        for i, j in zip([0, 0, -1, 1], [-1, 1, 0, 0]): +            if (0 <= h_ + i < H) and (0 <= w_ + j < W): +                if checked[h_ + i][w_ + j]: +                    continue +                checked[h_ + i][w_ + j] = True +                if s[h_ + i][w_ + j] == ".": +                    q.append((h_ + i, w_ + j, n + 1)) +    return g_n + + +n = 0 +for i in range(H): +    for j in range(W): +        n = max(n, bfs(i, j)) +print(n)