// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;
int n;
inline int prim(unsigned long long int n)
{
	int d = 2;
	if (n < 2 || (n % 2 == 0 && n>2))
		return 0;
	while (d*d <= n)
	{
		if (n%d == 0)
			return 0;
		d++;
	}
	return 1;
}
int _tmain()
{
	do{ cin >> n; } while (!(n >= 2 && n <= 1000000000));
	if (n == 4)
		cout << 2 << endl;
	else
		if (prim(n))
			cout << n - 1 << endl;
		else
			cout << 0<<endl;
	system("pause");
	return 0;
}