# coding:utf-8

(h, w) = [int(i) for i in input().rstrip().split(" ")]
map = [input().rstrip() for i in range(h)]

index_map = [[i * w + j for j in range(w)] for i in range(h)]
rev_index_map = [(int(i / w), i % w) for i in range(h * w)]
diff = [[h * w + 1 for i in range(h * w)] for j in range(h * w)]


def isSame(r1, c1, r2, c2):
    if r1 != r2:
        return False
    if c1 != c2:
        return False
    return True


def isNear(r1, c1, r2, c2):
    if r1 == r2:
        if abs(c1 - c2) == 1:
            return True
    elif abs(r1 - r2) == 1:
        if c1 == c2:
            return True
    return False


ans = 0

for idx1 in range(h * w):
    for idx2 in range(h * w):
        (r2, c2) = rev_index_map[idx2]
        if map[r2][c2] == "#":
            continue
        for idx3 in range(h * w):
            (r3, c3) = rev_index_map[idx3]
            if map[r3][c3] == "#":
                continue
            if isSame(r2, c2, r3, c3):
                diff[idx2][idx3] = 0
            elif isNear(r2, c2, r3, c3):
                diff[idx2][idx3] = 1
            else:
                tmp = dif[idx2][idx1] + diff[idx1][idx3]
                if diff[idx2][idx3] > tmp:
                    diff[idx2][idx3] = tmp

for i in diff:
    for j in i:
        if j > h*w:
            continuef
        ans = max(ans,j)
print(ans)
