def main():

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

    ans = 0
    mv = [[1,0], [-1,0], [0, 1], [0,-1]]
    for i in range(H):
        for j in range(W):
            if S[i][j] == ".":
                cnt = 0
                cur = [[i, j]]
                visited = set([i, j])
                while cur:
                    temp = []
                    for k, l in cur:
                        for dk, dl in mv:
                            k1, l1 = k+dk, l+dl
                            if 0<=k1<H and 0<=l1<W and S[k1][l1] == "." and (k1,l1) not in visited:
                                visited.add((k1,l1))
                                temp.append([k1, l1])
                    cur = temp
                    if len(cur) > 0: cnt += 1
                ans = max(ans, cnt)
    return ans


if __name__ == '__main__':
    print(main())
