import numpy as np
from collections import deque
from itertools import product

h, w = map(int, input().split())
S = np.array([['' for i in range(w)] for j in range(h)])
for i in range(h):
  line = input()
  for j in range(w):
    S[i][j] = line[j]
#print(S)
  
di = [-1, 0, 1, 0]
dj = [0, 1, 0, -1]

q = deque()

def update(vs, i, j, x, q):
  if vs[i, j] != np.inf or S[i, j] == '#':
    return
  vs[i, j] = x
  q.append((i,j))

mx = 0
for i, j in product(range(h), range(w)):
  if S[i, j] == '#':
    continue
  vs = np.array([[np.inf for i in range(w)] for j in range(h)])
  x = 0
  update(vs, i, j, x , q)
  while len(q) > 0:
    #print(q)
    #print(vs)
    # x += 1
    current_q = q.popleft()
    qi, qj = current_q[0], current_q[1]
    for k in range(4):
      ni, nj = qi + di[k], qj + dj[k]
      if not(0 <= ni < h) or not(0 <= nj < w):
        continue
      update(vs, ni, nj, vs[qi][qj]+1, q)
  for i, j in product(range(h), range(w)):
    if vs[i,j] == np.inf: continue
    mx = max(mx, vs[i,j])
print(int(mx))
      