# 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)]
diff = [[h*w+1 for i in range(h*w)] for j in range(h*w)]

for r1 in range(h):
    for c1 in range(w):
        idx1 = index_map[r1][c1]
        for r2 in range(h):
            for c2 in range(w):
                idx2 = index_map[r2][c2]
                if map[r2][c2] == "#":
                    continue
                for r3 in range(h):
                    for c3 in range(w):
                        idx3 = index_map[r3][c3]
                        if map[r3][c3] == "#":
                            continue
                        if r2 == r3 and c2 == c3:
                            diff[idx2][idx3] = 0
                        elif r2 == r3 and abs(c2 - c3) == 1:
                            diff[idx2][idx3] = 1
                        elif c2 == c3 and abs(r2-r3) == 1:
                            diff[idx2][idx3] = 1
                        elif map[r1][c1] == "#":
                            continue
                        elif diff[idx2][idx3] > diff[idx2][idx1] + diff[idx1][idx3]:
                            diff[idx2][idx3] = diff[idx2][idx1] + diff[idx1][idx3]

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

