from queue import Queue
INF = 99999999999999999


H, W = map(int, input().split())
S = [input() for x in range(H)]


def m_distance(si, sj):
    if (S[si][sj] == '#'):
        return -INF
    
    q = Queue()
    q.put((si, sj, 0))
    done = [[False] * W for x in range(H)]

    m = 0
    unit = ((1, 0), (-1, 0), (0, 1), (0, -1))
    while not q.empty():
        i, j, w = q.get()
        done[i][j] = True
        

        for u in unit:
            nexti = i + u[0]
            nextj = j + u[1]
            if nexti >= 0 and nexti < H and nextj >= 0 and nextj < W and S[nexti][nextj] == '.' and (not done[nexti][nextj]):
                q.put((nexti, nextj, w+1))
                m = max(m, w+1)

    return m

m = 0
for i in range(H):
    for j in range(W):
        m = max(m, m_distance(i, j))
print(m)