Example

Input

3


Output

1
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


ll powmod(ll n,ll k,ll m){
	ll ret=1;
	while(k){
		if(k%2)ret=ret*n%m;
		n=n*n%m;
		k/=2;
	}
	return ret;
}
ll gcd(ll x,ll y){
	if(x<y)swap(x,y);
	return y?gcd(y,x%y) : x;
}
ll lcm(ll x,ll y){
	return x/gcd(x,y)*y;
}
int solve(){
	int n;
	cin>>n;
	ll N=n;
	if(n==2)return 1;
	int m=1;
	for(int i=2;i<100000;++i){
		if(n%i==0){
			n/=i;
			if(n%i==0)return -1;
			m=lcm(i-1,m);
		}
	}
	if(n>1)m=lcm(n-1,m);
	ll M=m;
	ll res=m;
	for(int i=2;i<=100000;++i){
		if(m%i==0){
			res/=i;
			res*=(i-1);
			while(m%i==0)m/=i;
		}
	}
	if(m>1){
		res/=m;
		res*=m-1;
	}
	ll ans=1e9;
	for(ll i=1;i<=100000;++i){
		if(res%i==0){
			if(powmod(N,i,M)==1)ans=min(ans,i);
			if(powmod(N,res/i,M)==1)ans=min(ans,res/i);
		}
	}
	if(ans<1e9)return ans;
	return -1;
}

int main(){
	cout<<solve()<<endl;
}
