#include <bits/stdc++.h>

using namespace std;

int solve(int n) {
	int ret = 1 % n;
	for (int i = 2; i <= n - 1; i++) {
		ret = ret * i % n;
	}
	return ret;
}

bool isPrime(int n) {
	for (int d = 2; d * d <= n; d++) {
		if (n % d == 0) {
			return false;
		}
	}
	return true;
}

int main() {
//	freopen("date.in", "r", stdin);
//	freopen("date.out","w", stdout);
	cin.sync_with_stdio(false);
	
//	for (int n = 1; n <= 100; n++) {
//		int ans = solve(n);
//		cout << n << ' ' << ans << '\n';
//	}
	
	int N;
	cin >> N;
	if (N == 4) {
		cout << 2 << endl;
	}
	else if (isPrime(N)) {
		cout << N - 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
	
	return 0;
}