import copy
from collections import deque
h, w = map(int, input().split())
mapping = [0]*h
for i in range(h):
  mapping[i] = input()

  
already = [[False]*w for i in range(h)]
for i in range(h):
  for j in range(w):
    if mapping[i][j] == "#":
      already[i][j] = True


ans = 0

for i in range(h):
  for j in range(w):
    if already[i][j]:
      continue
    
    yet = copy.deepcopy(already)
    yet[i][j] = True
    not_yet = deque([])
    
    depth = [[0]*w for i in range(h)]
    
    if i != 0 and not yet[i-1][j]:
        not_yet.append([i-1, j])
        depth[i-1][j] = 1
        yet[i-1][j] = True
    if i != h-1 and not yet[i+1][j]:
        not_yet.append([i+1, j])
        depth[i+1][j] = 1
        yet[i+1][j] = True
    if j != 0 and not yet[i][j-1]:
        not_yet.append([i, j-1])
        depth[i][j-1] = 1
        yet[i][j-1] = True
    if j != w-1 and not yet[i][j+1]:
        not_yet.append([i, j+1])
        depth[i][j+1] = 1
        yet[i][j+1] = True
    
    while len(not_yet) > 0:
        key = not_yet.popleft()
        a, b = key[0], key[1]
        
        if a != 0 and not yet[a-1][b]:
            not_yet.append([a-1, b])
            yet[a-1][b] = True
            depth[a-1][b] = depth[a][b]+1
            
        if a != h-1 and not yet[a+1][b]:
            not_yet.append([a+1, b])
            yet[a+1][b] = True
            depth[a+1][b] = depth[a][b]+1
            
        if b != 0 and not yet[a][b-1]:
            not_yet.append([a, b-1])
            yet[a][b-1] = True
            depth[a][b-1] = depth[a][b]+1
            
        if b != w-1 and not yet[a][b+1]:
            not_yet.append([a, b+1])
            yet[a][b+1] = True
            depth[a][b+1] = depth[a][b]+1
            
    k = 0
    for i in range(h):
        for j in range(w):
            if k < depth[i][j]:
                k = depth[i][j]
    if ans < k:
        ans = k

print(ans)