from collections import deque
def mazesolve(h,w,maze,start):
  visit = [[False]*(w+2) for _ in range(h+2)]
  query = deque([])
  query.append((start,0,visit))
  d = [(1,0),(0,1),(-1,0),(0,-1)]
  ret = 0
  while query:
    place,move,where = query.popleft()
    y,x = place
    ret = max(ret,move)
    where[y][x] = True
    for dy,dx in d:
      if maze[y+dy][x+dx] == "#" or where[y+dy][x+dx]:
        continue
      else:
        query.append(((y+dy,x+dx),move+1,where))
     
  return ret
def solve():
  h,w = (int(i) for i in input().split())
  if h == 1 and w == 1:
    print(0)
    exit()
  maze = ["#"*(w+2)]
  for i in range(h):
    maze.append("#" + input() + "#")
  maze.append("#"*(w+2))
  startgoal = []
  for i in range(w+1):
    if maze[1][i] == ".":
      startgoal.append((1,i))
    if maze[h][i] == ".":
      startgoal.append((h,i))
  for i in range(h+1):
    if maze[i][1] == ".":
      startgoal.append((i,1))
    if maze[i][w] == ".":
      startgoal.append((i,w))
  startgoal = sorted(list(set(startgoal)))
  ans = 0
  for i in range(len(startgoal)):
      start = startgoal[i]
      ans = max(ans,(mazesolve(h,w,maze,start)))
  print(ans)


solve()