import numpy as np
from itertools import product

h, w = map(int, input().split())
s = np.full((h, w), 'x', dtype='U1')
for i in range(h):
    s[i] = list(input())

d = np.full((h*w, w*h), float('inf'))
for i in range(h * w):
    d[i, i] = 0

for i, k in product(range(h), range(w)):
    if s[i, k] == '#':
        continue
    for dy, dx in ((-1, 0), (0, -1), (0, 1), (1, 0)):
        y, x = i + dy, k + dx
        if y < 0 or h <= y or x < 0 or w <= x or s[y, x] == '#':
            continue
        d[i*w+k, y*w+x] = 1
        d[y*w+x, i*w+k] = 1

# warshall-floyd
for k, i, j in product(range(h * w), repeat=3):
    d[i, j] = min(d[i, j], d[i, k] + d[k, j])

print(d.astype('i8').max())
