H, W = map(int, input().split())
S = []
for i in range(H):
    r = input()
    S.append(list(r))


def f(v1, v2):
    m = []
    for i in range(H):
        m.append([None]*W)
    m[v1][v2] = 0

    flag = True
    while flag:
        flag = False
        for i in range(H):
            for j in range(W):
                if S[i][j] == '#':
                    continue
                elif m[i][j] == None:
                    flag = True
                    continue
                else:
                    cur = m[i][j]
                    u = i-1
                    if 0 <= u and S[u][j] == '.':
                        if m[u][j] is None:
                            m[u][j] = cur + 1
                        m[u][j] = min(m[u][j], cur+1)
                    d = i+1
                    if d <= H-1 and S[d][j] == '.':
                        if m[d][j] is None:
                            m[d][j] = cur + 1
                        m[d][j] = min(m[d][j], cur+1)
                    l = j-1
                    if 0 <= l and S[i][l] == '.':
                        if m[i][l] is None:
                            m[i][l] = cur + 1
                        m[i][l] = min(m[i][l], cur+1)
                    r = j+1
                    if r <= W-1 and S[i][r] == '.':
                        if m[i][r] is None:
                            m[i][r] = cur + 1
                        m[i][r] = min(m[i][r], cur+1)

    ans = 0
    for i in range(H):
        for j in range(W):
            if m[i][j] == None:
                continue
            else:
                ans = max(ans, m[i][j])
    return ans

r = -1
#　スタート位置
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        else:
            x = f(i, j)
            r = max(r, x)
            # print(x)
print(r)