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

def check():
  for y in range(H):
    for x in range(W):
      m = M[y][x]
      if m == ".":
        return x,y

st_x,st_y = check()

went = {(st_x,st_y):0}
q = [(st_x,st_y)]
idx = 0
while idx<len(q):
  x,y = q[idx]
  for dx,dy in [(0,-1),(0,1),(-1,0),(1,0)]:
    if (x+dx, y+dy) not in went.keys()  and 0<=x+dx<W and 0<= y+dy<H and M[y+dy][x+dx] == ".":
      q.append((x+dx,y+dy))
      went[(x+dx,y+dy)]=went[(x,y)]+1
  idx+=1

went = {(x,y):0}
q = [(x,y)]
idx = 0
while idx<len(q):
  x,y = q[idx]
  for dx,dy in [(0,-1),(0,1),(-1,0),(1,0)]:
    if (x+dx, y+dy) not in went.keys() and 0<=x+dx<W and 0<= y+dy<H and M[y+dy][x+dx] == ".":
      q.append((x+dx,y+dy))
      went[(x+dx,y+dy)]=went[(x,y)]+1
  idx+=1
  
went = {(x,y):0}
q = [(x,y)]
idx = 0
while idx<len(q):
  x,y = q[idx]
  for dx,dy in [(0,-1),(0,1),(-1,0),(1,0)]:
    if (x+dx, y+dy) not in went.keys() and 0<=x+dx<W and 0<= y+dy<H and M[y+dy][x+dx] == ".":
      q.append((x+dx,y+dy))
      went[(x+dx,y+dy)]=went[(x,y)]+1
  idx+=1
print(max(went.values()))
