# coding:utf-8

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

diff = [[401 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 r1 in range(h):
    for c1 in range(w):
        if map[r1][c1] == "#":
            continue
        idx1 = r1*w+c1
        for r2 in range(h):
            for c2 in range(w):
                if map[r2][c2] == "#":
                    continue
                idx2 = r2*w+c2
                for r3 in range(h):
                    for c3 in range(w):
                        if map[r3][c3] == "#":
                            continue
                        idx3 = r3*w+c3
                        if isSame(r2, c2, r3, c3):
                            diff[idx2][idx3] = 0
                        elif isNear(r2, c2, r3, c3):
                            diff[idx2][idx3] = 1
                        else:
                            tmp = diff[idx2][idx1] + diff[idx1][idx3]
                            if tmp < diff[idx2][idx3]:
                                diff[idx2][idx3] = tmp

for i in range(h*w):
    for j in range(i+1, h*w):
        num = diff[i][j]
        if num > h*w:
            continue
        ans = max(ans,num)
print(ans)
