arg=`cat`

echo | awk '{for(i=1;i<=32;i++){t = t 7;print t}}' | factor |\
awk '\
{
   N = split($0,A);
   NO[NR] = N
   for(i=2;i<=N;i++){
       D[NR,i] = A[i];
   }
}
END{
    if(arg==1){
        print 1
        exit;
    }
    if(arg%2==0||arg%5==0){
        print -1;
        exit
    }
    for(i=1;i<=NR;i++){
        for(j=1;j<lshift(1,NO[i]);j++){
            t = 1;
            for(k=1;k<=NO[i];k++){
                if(and(lshift(1,k-1), j)){
                    t *= D[i,k]
                }
            }
            if(t==0)continue
            if(t%arg==0){
                print i
                exit;
            }
        }
    }
    print arg-1
}' arg=$arg
