import copy
import numpy as np
from collections import deque
m,n = list(map(int, input().split()))
o2 = []
dist_mat = []
for i in range(m):
    o1 = list(str(input()))
    o2.append(o1)
    dist_mat.append(np.zeros(len(o1)))

in_mat = np.array(o2)
#dist_mat = np.zeros_like(in_mat)
dist_mat = []
for i in in_mat:
    dist_mat.append(np.zeros(len(i)))
dist_mat = np.array(dist_mat)
rows,cols = dist_mat.shape

qu = deque()

for r in range(rows):
    for c in range(cols):
        if in_mat[r][c] == ".":
            qu.appendleft((r,c))

dist_mat_base = copy.deepcopy(dist_mat)

ans = []
lenqu = len(qu)
for i in range(lenqu):
    print(i)
    strt = qu.pop()
    qu2 = deque()
    qu2.appendleft(strt)
    dist_mat = copy.deepcopy(dist_mat_base)

    while qu2:
        curr_r, curr_c = qu2.pop()
        dist = dist_mat[curr_r][curr_c]
        adj_cells = [(0,1), (1,0), (0,-1), (-1,0)]
        for r_adj, c_adj in adj_cells:
            adj_row = curr_r + r_adj
            adj_col = curr_c + c_adj
            if 0 <= adj_row < rows and 0 <= adj_col < cols:
                if dist_mat[adj_row][adj_col] == 0 and in_mat[adj_row][adj_col] == "." and not (adj_row, adj_col) == strt:
                    dist_mat[adj_row][adj_col] = dist + 1
                    qu2.appendleft((adj_row, adj_col))

    dist_vec = np.concatenate(dist_mat)
    ans.append(round(max(dist_vec)))

print(round(max(ans)))