h, w = map(int,input().split())
way = []
for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == ".":
            way.append(i*w+j)
wayn = len(way)
mat = 0

for i in way:
    al = [i]
    time = 0
    pp = [i]
    while not len(al) == wayn:
        np = [j for j in pp]
        pp = []
        for j in np:
            if j%w < w-1 and j+1 in way and (not j+1 in al) and (not j+1 in pp):
                pp.append(j+1)
                al.append(j+1)
            if j%w > 0 and j-1 in way and (not j-1 in al) and (not j-1 in pp):
                pp.append(j-1)
                al.append(j-1)
            if j//w < h-1 and j+w in way and (not j+w in al) and (not j+w in pp):
                pp.append(j+w)
                al.append(j+w)
            if j//w > 0 and j-w in way and (not j-w in al) and (not j-w in pp):
                pp.append(j-w)
                al.append(j-w)
        time += 1
    if time > mat:
        mat = time

print(mat)
