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

D = (W,-W,1,-1)
cnt = 0

def furthest(i):
    global cnt
    cnt += 1
    q = [i]
    visited[i] = cnt

    u = None
    for dist in count():
        if not q:
            break
        u = q[0]
        nq = []
        for j in q:
            for d in D:
                if visited[j+d] < cnt:
                    visited[j+d] = cnt
                    nq.append(j+d)
        q = nq
    return dist, u

res = 1
for i in range(W*H):
    if visited[i] != 0:
        continue
    _,u = furthest(i)
    d,_ = furthest(u)
    res = max(res, d)

print(res-1)