#!/bin/bash

arg=`cat`

echo | awk '{for(i=1;i<=32;i++){t = t 7;print t}}' |\
factor | nl |\
awk '\
{
   N=split($0,A);
   for(i=3;i<=N;i++){
       if(D[A[i]]=="")D[A[i]]=A[1]
   }
}
END{
    if(arg%2==0){
        print -1;
        exit
    }
    for(i in D){
        if(i==arg){
            print D[i];
            exit;
        }
    }
    print arg-1
}' arg=$arg
