#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int check(int n)
{
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			int cnt = 0;
			while (n % i == 0) {
				n /= i;
				cnt++;
			}
			if (cnt > 1) return 1;
		}
	}
	return 0;
}

vector<int> factorize(int n)
{
	vector<int> res;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			res.push_back(i);
			while (n % i == 0) n /= i;
		}
	}
	if (n > 1) res.push_back(n);
	return res;
}

// 求n的欧拉函数值，简易版
// sqrt(n)
int get(int n){
    int i,m=n;
    for(i=2;i*i<=n;i++) if(n%i==0)
        for(m=m/i*(i-1);n%i==0;n/=i);
    if(n>1) m=m/n*(n-1);
    return m;
}

LL POW(LL a, LL b, LL MOD)
{
	LL res = 1;
	while (b) {
		if (b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

void update(int n, int MOD, int k, int &now)
{
	LL res = POW(n, k, MOD);
	if (res != 1) return;
	if (now == -1 || k < now) now = k;
}

int main()
{
	int n;
	while (scanf("%d", &n) != EOF) {
		if (n == 2) {
			puts("1");
			continue;
		}
		if (check(n)) {
			puts("-1");
			continue;
		}
		vector<int> Q = factorize(n);
		vector<int> U;
		int tag = 0;
		for (int &p : Q) {
			if (__gcd(n, p - 1) != 1) {
				tag = 1;
				break;
			}
			int phi = get(p - 1);
			int now = -1;
			for (int i = 1; i * i <= phi; i++) {
				if (phi % i == 0) {
					update(n, p - 1, i, now);
					update(n, p - 1, phi / i, now);
				}
			}
			if (now == -1) {
				tag = 1;
				break;
			}
			U.push_back(now);
		}
		if (tag) {
			puts("-1");
			continue;
		}
		int LCM = 1;
		for (int &x : U) {
			LCM = LCM / __gcd(LCM, x) * x;
		}
		printf("%d\n", LCM);
	}
	return 0;
}

