// bash game
#include <stdio.h>
#include <memory>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <time.h>
#include <limits>
using namespace std;
int cal(int a){
int b, ans;
ans = inf;
for(b = 1; b * b <= a; b++){
if(!(a % b)){
if(b > 2 && b < ans) ans = b;
if((a / b) > 2 && (a / b) < ans) ans = (a / b);
}
}
if(ans < inf) return ans - 1;
else return a - 1;
}
int main(){
#ifndef ONLINE_JUDGE
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
init();
int a;
while(~scanf("%d", &a)){
printf("%d\n", cal(a));
}
return 0;
}