from collections import deque

def main():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    ans = 0
    dh = [0,1,0,-1]
    dw = [1,0,1,0]
    for h in range(H):
        for w in range(W):
            if S[h][w] == '#':
                continue
            dist = [[float('inf')] * W for _ in range(H)]
            dist[h][w] = 0
            cnt = 0
            Q = deque()
            Q.append([h,w])
            while Q:
                x, y = Q.popleft()
                for i in range(4):
                    nh = x + dh[i]
                    nw = y + dw[i]
                    if 0 <= nh < H and 0 <= nw < W and dist[nh][nw] == float('inf') and S[nh][nw] == '.':
                        dist[nh][nw] = min(dist[x][y] + 1, dist[nh][nw])
                        cnt = max(cnt, dist[nh][nw])
                        Q.append([nh,nw])
            ans = max(ans, cnt)

    print(ans)



if __name__ == "__main__":
    main()