#include <iostream>
#include <cmath>

using namespace std;

bool prime(int x)
{
	if (x == 2)
	{
		return true;
	}
	if (x % 2 == 0)
	{
		return false;
	}

	int end = (int)(sqrt(x));
	for (int i = 3; i <= end; i += 2)
	{
		if (x % i == 0)
		{
			return false;
		}
	}

	return true;
}

int main()
{
	int x;
	cin >> x;

	if (x == 4)
	{
		cout << 2;
	}
	else if (prime(x))
	{
		cout << x - 1;
	}
	else
	{
		cout << 0;
	}

	return 0;
}