from collections import deque
h,w = map(int,input().split())
G = [input() for i in range(h)]
directions = [(1,0),(0,1),(-1,0),(0,-1)]
ans = 0

for sx in range(w):
  for sy in range(h):
    if G[sy][sx] == "#":
      continue
      
    dist = [[-1] * w for i in range(h)]
    dist[sy][sx] = 0
    que = deque([[sy, sx]])
    
    while len(que):
      y,x = que.popleft()
      for dx,dy in directions:
        nx = x + dx
        ny = y+ dy
        if not (0<=nx<w and 0<=ny<h) or G[ny][nx]=="#":
          continue
        if dist[ny][nx] != -1:
          continue
      
        dist[ny][nx] = dist[y][x] +1
        que.append([ny,nx])
      
    ans = max(ans, max([max(d) for d in dist]))
    
print(ans)