def main():
    from collections import deque

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

    s = [input() for _ in range(h)]

    drdc = (1, 0), (-1, 0), (0, 1), (0, -1)

    dist = [[-1] * w for _ in range(h)]

    vs = []
    for r in range(h):
        for c in range(w):
            if dist[r][c] == -1 and s[r][c] == '.':
                dist[r][c] = 0

                q = deque()
                q.append((r, c, 0))

                md = -1
                tr, tc = -1, -1
                while q:
                    qr, qc, d = q.popleft()
                    for dr, dc in drdc:
                        nr = qr + dr
                        if nr < 0 or h <= nr:
                            continue
                        nc = qc + dc
                        if nc < 0 or w <= nc:
                            continue
                        if s[nr][nc] == '#':
                            continue
                        if dist[nr][nc] != -1:
                            continue
                        nd = d + 1
                        dist[nr][nc] = nd
                        if md < nd:
                            md = nd
                            tr = nr
                            tc = nc

                        q.append((nr, nc, nd))

                if tr != -1:
                    vs.append((tr, tc))

    dist = [[-1] * w for _ in range(h)]

    max_d = -1
    for sr, sc in vs:
        q = deque()
        q.append((sr, sc, 0))
        dist[sr][sc] = 0

        while q:
            r, c, d = q.popleft()
            for dr, dc in drdc:
                nr = r + dr
                if nr < 0 or h <= nr:
                    continue
                nc = c + dc
                if nc < 0 or w <= nc:
                    continue
                if s[nr][nc] == '#':
                    continue
                if dist[nr][nc] != -1:
                    continue
                nd = d + 1
                dist[nr][nc] = nd
                if max_d < nd:
                    max_d = nd
                q.append((nr, nc, nd))

    print(max_d)


if __name__ == '__main__':
    main()
