#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

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

ll inv( ll a , ll mod ){
  ll x, y;
  if( extgcd( a , mod , x , y ) != 1 ){
    throw 0;
  }
  x %= mod;
  if( x < 0 ){
    x += mod;
  }
  return x;
}

ll modlog( ll n , ll mod ){
  ll q = 1;
  while( q * q < mod ){
    q++;
  }
  n %= mod;
  map<ll,ll> ma;
  ll nq = 1;
  ma[1] = 0;
  REP( i , q ){
    nq = ( nq * n ) % mod;
    if( nq == 1 ){
      return i + 1;
    }
    ll a = ( inv( nq , mod ) ) % mod;
    if( ma.find( a ) == ma.end() ){
      ma[a] = i + 1;
    }
  }
  ll cur = 1;
  REP( i , q ){
    cur = ( cur * nq ) % mod;
    if( ma.find( cur ) != ma.end() ){
      return ( i + 1 ) * q + ma[cur];
    }
  }
  assert( false );
}

vl fact( ll x ){
  vl res;
  for( ll i = 2; i*i <= x; i++ ){
    while( x % i == 0 ){
      res.pb( i );
      x /= i;
    }
  }
  if( x > 1 ) res.pb( x );
  return res;
}

ll f( ll a , ll b , ll mo ){
  // a k = b mod mo
  // a k + mo l = b
  ll g = __gcd( a , mo );
  if( b % g != 0 ){
    return -1;
  }
  a /= g;
  b /= g;
  mo /= g;
  // cout << "* " << a << " " << mo << endl;
  ll k, l;
  extgcd( a , mo , k , l );
  // cout << "* " << k << " " << l << endl;
  k *= b;
  l *= b;
  k = ( ( k % mo ) + mo ) % mo;
  return k;
}

ll n;


int main(){
  
  n = in();

  vl v = fact( n );
  SORT( v );
  REP( i , SZ(v) - 1 ){
    if( v[i] == v[i+1] ){
      puts( "-1" );
      return 0;
    }
  }
  
  ll x = 1;
  ll y = 0;
  ll ans = 1;
  REP( i , SZ(v) ){
    ll mod = v[i] - 1;
    if( mod == 1 ){
      continue;
    }
    try{
      ll res = modlog( n , mod );
      if( res == -1 ){
        puts( "-1" );
        return 0;
      }
      ll r = f( x , ( ( res - y ) % mod + mod ) % mod, mod );
      // cout << r << " " << mod << endl;
      ans = ans * r / __gcd( ans , r );
      /*
      SHOW( x );
      SHOW( y );
      SHOW( res );
      SHOW( mod );
      cout << res << " " << mod << " " << r << endl;
      ll nx = x * mod;
      ll ny = x * r + y;
      x = nx;
      y = ny;
      y = ( ( y % x ) + x ) % x;
      cout << x << " " << y << endl;
      */
    } catch (...){
      puts( "-1" );
      return 0;
    }
  }

  if( ans == 0 ){
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  /*
  if( y == 0 ){
  cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  */

  return 0;
}
 

Measured memory_bytes: 4356