Example

Input

3


Output

1
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}

ll gcd(ll a,ll b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

//BEGIN CUT HERE

template<typename T>
T extgcd(T a,T b,T &x,T &y){
  T d=a;
  if(b!=0){
    d=extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }else{
    x=1;
    y=0;
  }
  return d;
}

template<typename T>
T mod_inverse(T a,T mod){
  T x,y;
  extgcd(a,mod,x,y);
  return (mod+x%mod)%mod;
}

template<typename T>
pair<T, T> linear_congruence(const vector<T> &A,
                             const vector<T> &B,
                             const vector<T> &M){
  T x=0,m=1;
  for(int i=0;i<(int)A.size();i++){
    T a=A[i]*m,b=B[i]-A[i]*x,d=__gcd(M[i],a);
    if(b%d!=0) return make_pair(0,-1);
    T t=b/d*mod_inverse(a/d,M[i]/d)%(M[i]/d);
    x=x+m*t;
    m*=M[i]/d;
  }
  return make_pair((x%m+m)%m,m);
}
//END CUT HERE

//BEGIN CUT HERE
template<typename T>
T totient(T n){
  T res=n;
  for(T i=2;i*i<=n;i++){
    if(n%i==0){
      res=res/i*(i-1);
      for(;n%i==0;n/=i);
    }
  }
  if(n!=1) res=res/n*(n-1);
  return res;
}
//END CUT HERE

ll mod_pow(ll a,ll x,ll mod){
  ll ret=1;
  a%=mod;
  while(x>0){
    if(x&1){
      (ret*=a)%=mod;
    }
    (a*=a)%=mod;
    x>>=1;
  }
  return ret;
}

int main(){
  ll N,tmp;
  cin>>N;
  tmp=N;
  vector<ll> P;
  for(ll i=2;i*i<=tmp;i++){
    while(tmp%i==0){
      if(!P.empty() && P.back()==i){
        cout<<-1<<endl;
        return 0;
      }
      P.push_back(i);
      tmp/=i;
    }
  }
  if(tmp!=1){P.push_back(tmp);}
  vector<ll> A,B,M;
  ll ans=1;
  for(auto &I:P){
    if(I-1==1){continue;}
    if(gcd(N,I-1)!=1){
      cout<<-1<<endl;
      return 0;
    }
    ll phi=totient(I-1);
    ll mi=phi;
    if(mod_pow(N,phi,I-1)!=1){
      cerr<<N<<" "<<phi<<" "<<I-1<<" "<<mod_pow(N,phi,I-1)<<endl;
    }
    assert(mod_pow(N,phi,I-1)==1);
    for(ll i=1;i*i<=phi;i++){
      if(phi%i==0){
        if(mod_pow(N,i,I-1)==1){mi=min(mi,i);}
        if(mod_pow(N,phi/i,I-1)==1){mi=min(mi,phi/i);}
      }
    }
    ans=ans/gcd(ans,mi)*mi;
  }
  cout<<ans<<endl;
  
  
  return 0;
}

