from itertools import count, combinations, product

H,W = map(int,input().split())

H += 2
W += 2

visited = [2**31]*(W*H)

for i in range(1,H-1):
    S = input()
    for j,v in zip(range(1,W-1),S):
        if v == '.':
            visited[i*W + j] = 0

res = 1
D = (W,-W,1,-1)

for i in range(W*H):
    if visited[i] == 2**31:
        continue
    q = [i]
    visited[i] = i
    for dist in count():
        if not q:
            break
        nq = []
        for j in q:
            for d in D:
                if visited[j+d] < i:
                    visited[j+d] = i
                    nq.append(j+d)
        q = nq
    res = max(dist, res)

print(res-1)