# coding:utf-8

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

map = [mapSrc[int(i/w)][i%w] for i in range(h*w)]
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

for idx1 in range(h*w):
    if map[idx1] == "#":
        continue
    r1 = int(idx1/w)
    c1 = idx1 % w
    for idx2 in range(h*w):
        if map[idx2] == "#":
            continue
        r2 = int(idx2/w)
        c2 = idx2 % w
        for idx3 in range(idx2 + 1, h*w):
            if map[idx3] == "#":
                continue
            r3 = int(idx3/w)
            c3 = idx3 % w

            if idx2 == idx3:
                diff[idx2][idx3] = 0
            elif isNear(r2,c2,r3,c3):
                diff[idx2][idx3] = 1
                diff[idx3][idx2] = 1
            else:
                tmp = diff[idx2][idx1] + diff[idx1][idx3]
                if diff[idx2][idx3] > tmp:
                    diff[idx2][idx3] = tmp
                    diff[idx3][idx2] = tmp

ans = 0

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)
