H,W = (int(x) for x in input().split())
a = []
que = []
dis =[]
longDis = 0

for i in range(H):
    a += list(input().split())

h = -1
w = 0

for _ in range(H*W):
    k = 0
    dis = [k]
    l = 0

    if h < H-1:
        h += 1
    else:
        h = 0
        w += 1

    if a[h][w] != '.':
        continue

    que += [[h,w]]
    i = h
    j = w
    
    while True:
        k = dis[l] + 1

        #上
        if i-1 >= 0 and a[i-1][j] =='.':
            if [i-1,j] not in que:
                que += [[i-1,j]]
                dis += [k]

        #下
        if i+1 < H and a[i+1][j] == '.':
            if [i+1,j] not in que:
                que += [[i+1,j]]
                dis += [k]

        #左
        if j-1 >= 0 and a[i][j-1] == '.':
            if [i,j-1] not in que:
                que += [[i,j-1]]
                dis += [k]

        #右
        if j+1 < W and a[i][j+1] == '.':
            if [i,j+1] not in que:
                que += [[i,j+1]]
                dis += [k]

        l += 1

        if l == len(que):
            break
        
        i = que[l][0]
        j = que[l][1]

        if k > longDis:
            longDis = k

    dis.clear()
    que.clear()

print(longDis)
