h,w=map(int, input().split())
s=[None]*h*w
for i in range(h*w):
    s[i]=[int(1e6)]*h*w
for i in range(h):
    l=input()
    for j,x in enumerate(l):
        if x == '#':
            continue
        pos=w*i+j
        s[pos][pos]=0
        if pos % w != 0:
            s[pos][pos-1]=1
            s[pos-1][pos]=1
        if 0 <= pos-w:
            s[pos][pos-w]=1
            s[pos-w][pos]=1
for k in range(h*w):
    for i in range(h*w):
        for j in range(h*w):
            s[i][j] = min(s[i][j], s[i][k] + s[k][j])
m = 0
for x in s:
    m = max(m, max(x))
print(m)