H,W = map(int,input().split())
S = [input() for i in range(H)]
from collections import deque

dxy = [(0,1),(1,0),(0,-1),(-1,0)]
q = deque([(0,0)])
dist = [[0]*W for i in range(H)]
visited = [[0]*W for i in range(H)]
visited[0][0] = 1
mxx = mxy = -1
mxd = 0
while q:
    x,y = q.popleft()
    for dx,dy in dxy:
        nx,ny = x+dx,y+dy
        if not 0 <= nx < W: continue
        if not 0 <= ny < H: continue
        if visited[ny][nx]: continue
        if S[ny][nx] == '#': continue
        visited[ny][nx] = 1
        dist[ny][nx] = dist[y][x] + 1
        if dist[ny][nx] > mxd:
            mxd = dist[ny][nx]
            mxx = nx
            mxy = ny
        q.append((nx,ny))

q = deque([(mxx,mxy)])
dist = [[0]*W for i in range(H)]
visited = [[0]*W for i in range(H)]
visited[mxy][mxx] = 1
mxd = 0
while q:
    x,y = q.popleft()
    for dx,dy in dxy:
        nx,ny = x+dx,y+dy
        if not 0 <= nx < W: continue
        if not 0 <= ny < H: continue
        if visited[ny][nx]: continue
        if S[ny][nx] == '#': continue
        visited[ny][nx] = 1
        dist[ny][nx] = dist[y][x] + 1
        if dist[ny][nx] > mxd:
            mxd = dist[ny][nx]
        q.append((nx,ny))

print(max(max(row) for row in dist))