import queue

h, w = list(map(int, input().split()))
s = [input() for _ in range(h)]
q = queue.Queue()
q.put(0)
kyori = [0] * (h*w)
kyori[0] = 1
for i in range(2):
    while not q.empty():
        p = q.get()
        kyo = kyori[p]
        x = p%w
        y = p//w
        if x >= 1 and s[y][x-1] == '.' and kyori[p-1] == 0:
            q.put(p-1)
            kyori[p-1] = kyo+1
        if x < w-1 and s[y][x+1] == '.' and kyori[p+1] == 0:
            q.put(p+1)
            kyori[p+1] = kyo+1
        if y >= 1 and s[y-1][x] == '.' and kyori[p-w] == 0:
            q.put(p-w)
            kyori[p-w] = kyo+1
        if y < h-1 and s[y+1][x] == '.' and kyori[p+w] == 0:
            q.put(p+w)
            kyori[p+w] = kyo+1
    if i == 0:
        start = kyori.index(max(kyori))
        q = queue.Queue()
        q.put(start)
        kyori = [0] * (h*w)
        kyori[start] = 1
print(max(kyori)-1)