from collections import deque
import copy
H, W = map(int, input().split())
 
route = []
for _ in range(H):
  route.append(input())
  
wall = set()
start = set()
for y, r in enumerate(route):
  for x, w in enumerate(r):
    if w == '#':
      wall.add((x, y))
    else:
      start.add((x, y))

score = -1
ssize = [(-1,0),(0,-1),(1,0),(0,1)]
for xy in start:
  d = deque()
  d.append((xy+(0,)))
  step = 0
  already = copy.deepcopy(wall)
  while len(d) > 0:
    now = d.popleft()
    already.add(now[:-1])
    step = now[2]
    for xs, ys in ssize:
      nxt = (now[0]+xs, now[1]+ys)
      if nxt not in already and nxt in start:
        d.append(nxt+(step+1,))
  score = max(step, score)
  
print(score)