from queue import Queue

def solve(h, w, SS):
    m = {
        (x, y): S[x] == '.'
        for y, S in enumerate(SS)
        for x in range(len(S))
    }
    conditions = {
        (-1, 0): lambda x, y: x > 0,
        (1, 0): lambda x, y: x < w - 1,
        (0, -1): lambda x, y: y > 0,
        (0, 1): lambda x, y: y < h - 1
    }

    def calc_max_len(x0, y0):
        q = Queue(maxsize = h * w)
        q.put((x0, y0))
        d = {(x0, y0): 0}
        max_len = 0
        while not q.empty():
            x, y = q.get(block=False)
            for dx, dy in conditions.keys():
                key = (x + dx, y + dy)
                if conditions[(dx, dy)](x, y) and m[key] and key not in d:
                    q.put(key)
                    d[key] = d[(x, y)] + 1
            if max_len < d[(x, y)]:
                max_len = d[(x, y)]
        return max_len
    return max(calc_max_len(x, y) for x, y in m)

_h, _w = map(int, input().split())
_SS = [input() for _ in range(_h)]
print(solve(_h, _w, _SS))
