// Arup Guha
// 6/15/2023
// Solution to SIUCF CP Contest 2 Problem: Pascal
// https://open.kattis.com/problems/pascal

using namespace std;
#include <iostream>

int main() {

    int n;
    cin >> n;

    // Find smallest divisor greater than 1.
    int mindiv = 2;
    while (mindiv*mindiv <= n) {
        if (n%mindiv == 0) break;
        mindiv++;
    }

    // Special case.
    if (n%mindiv != 0) mindiv = n;

    // Get max divisor (other than n)
    int maxdiv = n/mindiv;

    // This is the result.
    cout << n - maxdiv << endl;

    return 0;
}
