Example

Input

3


Output

1
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long int;

ll gcd(ll N, ll M) {
    if(M == 0) return N;
    return gcd(M, N%M);
}

ll lcm(ll N, ll M) {
    return N / gcd(N, M) * M;
}

ll get_prod(ll N) {
    ll res = 1;
    for(int k=2; k*k<=N; k++) {
        int cnt = 0;
        while(N % k == 0) {
            cnt++; N /= k;
        }
        if(cnt > 1) return -1;
        else if(cnt == 1) res = lcm(res, k - 1);
    }
    if(N > 1) res = lcm(res, N - 1);
    return res;
}

// オイラーの φ 関数 (n 以下の自然数のうち n と互いに素なものの個数)
// \phi(n) = n \times \prod_{i=1}^{k} (1 - \frac{1}{p_i}) を使おう
// (ただし、 p_i は n の素因数)
// Complexity: O(sqrt n)
// Vefiried: AOJ NTL_1_D: Euler's Phi Function

ll Euler_phi(ll n) {
    ll ret = n;
    for(int i=2; i*i <= n; i++) {
        if(n % i == 0) {
            ret -= ret / i;
            while(n % i == 0) n /= i;
        }
    }
    if(n != 1) ret -= ret / n;
    return ret;
}

ll mod_pow(ll N, ll K, ll mod) {
    ll res = 1;
    for(; K>0; K>>=1) {
        if(K & 1) (res *= N) %= mod;
        (N *= N) %= mod;
    }
    return res;
}

int main() {
    ll N; cin >> N;
    ll prod = get_prod(N);
    if(prod < 0 or gcd(N, prod) > 1) {
        cout << -1 << endl;
    }
    else {
        ll euler = Euler_phi(prod);

        ll ans = euler;
        for(ll k=1; k*k<=euler; k++) {
            if(mod_pow(N, k, prod) == 1) {
                ans = min(ans, k);
            }
            if(mod_pow(N, euler/k, prod) == 1) {
                ans = min(ans, euler/k);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

