from collections import deque
h,w = map(int,input().rstrip().split())

def bsf(x,y,sy,sx):
  dx = [1,0,-1,0]
  dy = [0,1,0,-1]
  val = 0
  x[sx][sy] = 0
  cx = sx
  cy = sy
  d = deque()
  d.append((cx,cy))
  while d:
    cx,cy = d.popleft()
      
    for l in range(4):
      nx = cx + dx[l]
      ny = cy + dy[l]
      
      if 0 <= nx < h and 0 <= ny < w :
        if x[nx][ny] <= -1 and y[nx][ny] != '#':
          d.append((nx,ny))
          x[nx][ny] = x[cx][cy] + 1 

  return max(max(x))

#いけるとこといけないとこ
y = []
for i in range(h):
  y.append(list(input().rstrip()))

#初期迷路
x = [[-1] * w for _ in range(h)]


res = 0
for i in range(w):
  for j in range(h):
    sx = i 
    sy = j
    tmp = bsf(x,y,i,j)
    res = max(res,tmp)

print(res)
