from collections import deque
h,w = map(int,input().split())
maze = [list(input()) for i in range(h)]
ans = 0
for i in range(h):
  for j in range(w):
    if maze[i][j] == ".":
      visited = [[0 for k in range(w)] for l in range(h)]
      visited[i][j] = 1
      que = deque([])
      que.append((i,j,0))
      while que:
        (x,y,cnt) = que.popleft()
        for (nx,ny) in (x+1,y),(x-1,y),(x,y+1),(x,y-1):
          if 0<=nx<h and 0<=ny<w:
            if maze[nx][ny] == "." and visited[nx][ny] == 0:
              que.append((nx,ny,cnt+1))
              visited[nx][ny] = 1
      ans = max(ans,cnt)
print(ans)