from collections import deque
H,W=map(int,input().split())
S=[input() for i in range(H)]
flag=0
st=(-1,-1)
for i in range(H):
    for j in range(W):
        if S[i][j]==".":
            flag=1
            st=(i,j)
            break
    if flag==1:
        break
q=deque([st])
dx=[1,-1,0,0]
dy=[0,0,1,-1]
dist=[[-1 for j in range(W)] for i in range(H)]
dist[st[0]][st[1]]=0
while(len(q)>0):
    r=q.popleft()
    x,y=r
    for k in range(4):
        nx=x+dx[k]
        ny=y+dy[k]
        if 0<=nx<H and 0<=ny<W:
            if dist[nx][ny]==-1 and S[nx][ny]==".":
                dist[nx][ny]=dist[x][y]+1
                q.append((nx,ny))
for i in range(H):
    for j in range(W):
        if dist[st[0]][st[1]]<dist[i][j]:
            st=(i,j)
q=deque([st])
dx=[1,-1,0,0]
dy=[0,0,1,-1]
dist=[[-1 for j in range(W)] for i in range(H)]
dist[st[0]][st[1]]=0
while(len(q)>0):
    r=q.popleft()
    x,y=r
    for k in range(4):
        nx=x+dx[k]
        ny=y+dy[k]
        if 0<=nx<H and 0<=ny<W:
            if dist[nx][ny]==-1 and S[nx][ny]==".":
                dist[nx][ny]=dist[x][y]+1
                q.append((nx,ny))
print(max([max(i) for i in dist]))