h,w = map(int,input().split())

INF = 10 ** 18
grid = [input() for _ in range(h)]

ans = 0
for sy in range(h):
    for sx in range(w):
        if grid[sy][sx] == ".":
            for gy in range(h):
                for gx in range(w):
                    if sx == gx and sy == gy:
                        continue
                    if grid[gy][gx] == ".":

                        dist = [[INF] * w for _ in range(h)]
                        
                        dist[sy][sx] = 0
                        q = [(sy,sx)]
                        d = 1
                        
                        while q:
                          qq = []
                          for y,x in q:
                            for dy,dx in [(-1,0),(1,0),(0,-1),(0,1)]:
                              yy,xx = y+dy, x+dx
                              if not 0 <= xx < w:
                                  continue
                              if not 0 <= yy < h:
                                  continue
                              if grid[yy][xx] == '#':
                                continue
                              if dist[yy][xx] != INF:
                                continue
                              dist[yy][xx] = d
                              qq.append((yy,xx))
                          q = qq
                          d += 1
                        ans = max(ans, dist[gy][gx])

print(ans)
