from collections import deque
import numpy as np
H, W = map(int, input().split())

Q =deque()

M = []
M.append("#" * (W+2)) 
for i in range(H):
  M.append("#" + input() + "#")
  if M[i+1].find("."):
    x, y = i+1, M[i+1].find(".") + 2
M.append("#" * (W+2))
N = np.zeros((H+2,W+2))
dirs = [(-1,0),(1,0),(0,-1),(0,1)]
Q.append((x,y))
while Q:
  (x,y) = Q.pop()
  for a, b in dirs:
    if M[x+a][y+b] == "." and N[x+a][y+b] == 0 or N[x+a][y+b] > N[x][y]+1:
      N[x+a][y+b] = N[x][y] + 1
      Q.append((x+a, y+b))

idx = np.unravel_index(np.argmax(N), N.shape)
Q.append(idx)
N = np.zeros((H+2,W+2))
while Q:
  (x,y) = Q.pop()
  for a, b in dirs:
    if M[x+a][y+b] == "." and N[x+a][y+b] == 0 or N[x+a][y+b] > N[x][y]+1:
      N[x+a][y+b] = N[x][y] + 1
      Q.append((x+a, y+b))
print (int(np.max(N)))