H, W = map(int, input().split())
S = []

for ix in range(H):
    S.append(list(input()))


Dt = [(0,1), (1,0), (-1, 0), (0, -1)]
ans = 0
for x in range(H):
    for y in range(W):

        if S[x][y] == '#':
            continue
        # traverse
        sp = (x, y, 0)
        q = [sp]
        mxp = 0
        DP = [[0 for _ in range(W+1)] for __ in range(H+1)]

        while len(q) != 0:

            x, y, p = q[0]
            q.pop(0)

            if DP[x][y] != 0:
                continue
            else:
                DP[x][y] = 1

            if p > mxp:
                mxp = p

            for d in Dt:
                nx = x + d[0]
                ny = y + d[1]

                if nx < 0 or ny < 0 or nx >= H or ny >= W or S[nx][ny] == '#':
                    continue

                q.append((nx, ny, p + 1))

        if ans < mxp:
            ans = mxp

print(ans)