import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author sorin
 */
public class prog {

    public static void main(String[] args) throws FileNotFoundException {
       // File homedir = new File(System.getProperty("user.home"));

        // Scanner scanner = new Scanner(new File(homedir, "/Downloads/A-large.in"));
        /*Set<Long> set = new HashSet<>();
        
        for(int nr = 1000000000; nr >= 300000000; nr--) {
            if (isPrime(nr)) System.out.println( "set.add(" +nr+");");
        }*/
        
        Scanner scanner = new Scanner(System.in);
        long l = scanner.nextLong();
        if (l == 2) {
            System.out.println("1");
        } else if (l == 3) {
            System.out.println("2");
        } else if (l == 4) {
            System.out.println("2");
        } else if (l == 5) {
            System.out.println("4");
        } else if (isPrime(l)) {
            System.out.println(l - 1);
        } else {
            System.out.println("0");
        }
    }

    private static boolean isPrime(long n) {       
        
        for (long l = 2; l <= Math.sqrt(n) + 2 ; l++) {
            if (n % l == 0) return false;
        } 
        return true;
    }

}