#!/bin/awk -f

NR==1{H=$1; W=$2}
NR>1{
    for(i=1;i<=W;i++){
        t = substr($1,i,1);
        S[NR-1,i] = t
    }
}
function bfs(T,  R,r,x,y,j){
    for(j in T){
        U[j]++
        split(j,r,SUBSEP)
        x=r[1]; y=r[2];
        f=0
        if(S[x+1,y]=="." && !U[x+1,y]){
            R[x+1,y]++;f++;
        }
        if(S[x-1,y]=="." && !U[x-1,y]){
            R[x-1,y]++;f++;
        }
        if(S[x,y+1]=="." && !U[x,y+1]){
            R[x,y+1]++;f++;
        }
        if(S[x,y-1]=="." && !U[x,y-1]){
            R[x,y-1]++;f++;
        }
    }
    if(f==0){
        return 
    }
    n++
    bfs(R)
}
END{
    for(i=1;i<=H;i++){
        for(k=1;k<=W;k++){
            if(S[i,k]=="#")continue;
            delete T
            delete U
            T[i,k]++;
            U[i,k]++;
            bfs(T)
            max = n > max ? n: max
            n=0
        }
    }
    print max
}
