from collections import deque
def bfs(S,H,W,sh,sw):
    dist=[[-1]*W for i in range(H)]
    dist[sh][sw]=0

    d=deque()
    d.append([sh,sw])
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    while(len(d)!=0):
        h=d[0][0]
        w=d[0][1]
        d.popleft()
        for dir in range(4):
            nh=h+dx[dir]
            nw=w+dy[dir]
            if(nh>H-1 or nh<0 or nw>W-1 or nw<0):
                continue
            if(dist[nh][nw]!=-1 or S[nh][nw]=='#'):
                continue
            dist[nh][nw]=dist[h][w]+1
            d.append([nh,nw])
    return dist
    

H,W=map(int,input().split())
S=[input() for i in range(H)]
dis=bfs(S,H,W,0,0)
up=-2
for i in range(H):
    for j in range(W):
        up=max(up,dis[i][j])
        if(up==dis[i][j]):
            tx=i
            ty=j
dis2=bfs(S,H,W,tx,ty)
ans=-2
for i in range(H):
    for j in range(W):
        ans=max(ans,dis2[i][j])
print(ans)