// Arup Guha
// 11/14/2015
// Solution to 2015 SER D1/D2 Problem: The Magical 3

import java.util.*;

public class magical3 {

	public static void main(String[] args) {

		// Read in input minus 3.
		Scanner stdin = new Scanner(System.in);
		int x = stdin.nextInt()-3;

		// Finds smallest base that works in range [r,sqrt(x)].
		int best = x;
		for (int i=4; i<Math.sqrt(x)+.01; i++)  {
			if (x%i == 0) {
				best = i;
				break;
			}
		}

		// Trick cases.
		if (best == x) {
			if (x%3 == 0 && x/3 > 3) best = x/3;
			else if (x%2 == 0 && x/2 > 3) best = x/2;
		}

		// Output result.
		System.out.println(best);
	}
}
