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

S=[list(eval(input())) for i in range(H)]

m=0



for y in range(H):

  for x in range(W):

    if S[y][x]=="#":

      continue

    D=[[400]*W for i in range(H)]

    D[y][x]=0

    q=[]

    q.append([x,y])

    while len(q)>0:

      c=list(q.pop(0))

      for dx,dy in [[-1,0],[1,0],[0,-1],[0,1]]:

        if c[1]+dy<0 or c[1]+dy>=H:

          continue

        if c[0]+dx<0 or c[0]+dx>=W:

          continue

        if S[c[1]+dy][c[0]+dx]==".":

          if D[c[1]+dy][c[0]+dx]>D[c[1]][c[0]]+1:

            D[c[1]+dy][c[0]+dx]=D[c[1]][c[0]]+1

            q.append([c[0]+dx,c[1]+dy])

    A=[[D[y][x] if D[y][x]!=400 else -1 for x in range(W)] for y in range(H)]

    for i in range(H):

      m=max(m,max(A[i]))

print(m)
INF=10**9+7

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

S=list()

q=list()



S.append(["#"]*(W+2))

for i in range(H):

  S.append(["#"]+list(eval(input()))+["#"])

S.append(["#"]*(W+2))





m=0

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

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

    if S[y][x]=="#":

      continue

    D=[[INF]*(W+2) for _ in range(H+2)]

    D[y][x]=0

    q.clear()

    q.append([x,y])

    while len(q)>0:

      c=list(q.pop(0))

      for dx,dy in [[-1,0],[1,0],[0,-1],[0,1]]:

        ny,nx=c[1]+dy,c[0]+dx

        if S[ny][nx]=="." and D[ny][nx]==INF:

          D[ny][nx]=D[c[1]][c[0]]+1

          q.append([nx,ny])

          m=max(m,D[ny][nx])

print(m)

H, W = list(map(int, input().split()))
S = [list(eval(input())) for i in range(H)]
m = 0
for y in range(H):
    for x in range(W):
        if S[y][x] == "#":
            continue
        D = [[400] * W for i in range(H)]
        D[y][x] = 0
        q = []
        q.append([x, y])
        while len(q) > 0:
            c = list(q.pop(0))
            for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
                if c[1] + dy < 0 or c[1] + dy >= H:
                    continue
                if c[0] + dx < 0 or c[0] + dx >= W:
                    continue
                if S[c[1] + dy][c[0] + dx] == ".":
                    if D[c[1] + dy][c[0] + dx] > D[c[1]][c[0]] + 1:
                        D[c[1] + dy][c[0] + dx] = D[c[1]][c[0]] + 1
                        q.append([c[0] + dx, c[1] + dy])
        A = [[D[y][x] if D[y][x] != 400 else -1 for x in range(W)] for y in range(H)]
        for i in range(H):
            m = max(m, max(A[i]))
print(m)

INF = 10**9 + 7
H, W = list(map(int, input().split()))
S = list()
q = list()
S.append(["#"] * (W + 2))
for i in range(H):
    S.append(["#"] + list(eval(input())) + ["#"])
S.append(["#"] * (W + 2))
m = 0
for y in range(1, H + 1):
    for x in range(1, W + 1):
        if S[y][x] == "#":
            continue
        D = [[INF] * (W + 2) for _ in range(H + 2)]
        D[y][x] = 0
        q.clear()
        q.append([x, y])
        while len(q) > 0:
            c = list(q.pop(0))
            for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
                ny, nx = c[1] + dy, c[0] + dx
                if S[ny][nx] == "." and D[ny][nx] == INF:
                    D[ny][nx] = D[c[1]][c[0]] + 1
                    q.append([nx, ny])
                    m = max(m, D[ny][nx])
print(m)

+INF = 10**9 + 7 -S = [list(eval(input())) for i in range(H)] +S = list() +q = list() +S.append(["#"] * (W + 2)) +for i in range(H): +    S.append(["#"] + list(eval(input())) + ["#"]) +S.append(["#"] * (W + 2)) -for y in range(H): -    for x in range(W): +for y in range(1, H + 1): +    for x in range(1, W + 1): -        D = [[400] * W for i in range(H)] +        D = [[INF] * (W + 2) for _ in range(H + 2)] -        q = [] +        q.clear() -                if c[1] + dy < 0 or c[1] + dy >= H: -                    continue -                if c[0] + dx < 0 or c[0] + dx >= W: -                    continue -                if S[c[1] + dy][c[0] + dx] == ".": -                    if D[c[1] + dy][c[0] + dx] > D[c[1]][c[0]] + 1: -                        D[c[1] + dy][c[0] + dx] = D[c[1]][c[0]] + 1 -                        q.append([c[0] + dx, c[1] + dy]) -        A = [[D[y][x] if D[y][x] != 400 else -1 for x in range(W)] for y in range(H)] -        for i in range(H): -            m = max(m, max(A[i])) +                ny, nx = c[1] + dy, c[0] + dx +                if S[ny][nx] == "." and D[ny][nx] == INF: +                    D[ny][nx] = D[c[1]][c[0]] + 1 +                    q.append([nx, ny]) +                    m = max(m, D[ny][nx])