h, w = map(int, input().split())
s= [list(input()) for _ in range(h)]
 
visited = [[-1 for _ in range(w)] for _ in range(h)]

queue = []
mx = 0
for sy in range(h):
    for sx  in range(w):
        st=s[sy][sx]
        if st =="#":
            continue
        for gy  in range(h):
            for gx in range(w):
                gl = s[gy][gx]
                if gl =="#":
                    continue
                else:            
                    visited[sy][sx] = 0
                    queue.append((sy, sx))
                    while queue:
                          y, x = queue.pop(0)
                          for y_, x_ in [(y - 1, x), (y + 1, x), (y, x - 1), (y, x + 1)]:
                                if y_<0 or y_>=h or x_<0 or x_>= w:
                                    continue
                                else:
                                    if s[y_][x_] == '.':
                                      if visited[y_][x_] == -1:
                                        visited[y_][x_] = visited[y][x] + 1
                                        queue.append((y_, x_))
                if mx <visited[gy][gx]:
                    mx = visited[gy][gx]
print(mx)
    