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

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

from collections import deque

import numpy as np

ans = 0

for i in range(H):

  for j in range(W):

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

      continue

    inf = 10**5

    A = [[inf]*W for _ in range(H)]

    A[i][j]=0

    q = deque([[i,j]])

    while q:

      a = q.popleft()

      x=a[0]

      y=a[1]

      b = A[x][y]

      for m in [[x-1,y],[x+1,y],[x,y-1],[x,y+1]]:

        h = m[0]

        w = m[1]

        if (h<0)or(h>H-1)or(w<0)or(w>W-1):

          continue

        if S[h][w]=='#':

          continue

        c = b+1

        if c>=A[h][w]:

          continue

        A[h][w]=c

        q.append([h,w])

      

    A = np.array(A)

    ans = max(ans,max(A[A<10**5]))

    

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

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

from collections import deque

ans = 0

for i in range(H):

  for j in range(W):

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

      continue

    inf = 10**5

    A = [[inf]*W for _ in range(H)]

    A[i][j]=0

    q = deque([[i,j]])

    while q:

      a = q.popleft()

      x=a[0]

      y=a[1]

      b = A[x][y]

      for m in [[x-1,y],[x+1,y],[x,y-1],[x,y+1]]:

        h = m[0]

        w = m[1]

        if (h<0)or(h>H-1)or(w<0)or(w>W-1):

          continue

        if S[h][w]=='#':

          A[h][w]=0

          continue

        c = b+1

        if c>=A[h][w]:

          continue

        A[h][w]=c

        q.append([h,w])

        

    A = [a for b in A for a in b if a!=inf]

    ans = max(ans,max(A))

    

print(ans)
H, W = list(map(int, input().split()))
S = [list(eval(input())) for _ in range(H)]
from collections import deque
import numpy as np

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        inf = 10**5
        A = [[inf] * W for _ in range(H)]
        A[i][j] = 0
        q = deque([[i, j]])
        while q:
            a = q.popleft()
            x = a[0]
            y = a[1]
            b = A[x][y]
            for m in [[x - 1, y], [x + 1, y], [x, y - 1], [x, y + 1]]:
                h = m[0]
                w = m[1]
                if (h < 0) or (h > H - 1) or (w < 0) or (w > W - 1):
                    continue
                if S[h][w] == "#":
                    continue
                c = b + 1
                if c >= A[h][w]:
                    continue
                A[h][w] = c
                q.append([h, w])
        A = np.array(A)
        ans = max(ans, max(A[A < 10**5]))
print(ans)

H, W = list(map(int, input().split()))
S = [list(eval(input())) for _ in range(H)]
from collections import deque

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        inf = 10**5
        A = [[inf] * W for _ in range(H)]
        A[i][j] = 0
        q = deque([[i, j]])
        while q:
            a = q.popleft()
            x = a[0]
            y = a[1]
            b = A[x][y]
            for m in [[x - 1, y], [x + 1, y], [x, y - 1], [x, y + 1]]:
                h = m[0]
                w = m[1]
                if (h < 0) or (h > H - 1) or (w < 0) or (w > W - 1):
                    continue
                if S[h][w] == "#":
                    A[h][w] = 0
                    continue
                c = b + 1
                if c >= A[h][w]:
                    continue
                A[h][w] = c
                q.append([h, w])
        A = [a for b in A for a in b if a != inf]
        ans = max(ans, max(A))
print(ans)

-import numpy as np +                    A[h][w] = 0 -        A = np.array(A) -        ans = max(ans, max(A[A < 10**5])) +        A = [a for b in A for a in b if a != inf] +        ans = max(ans, max(A))