#include<iostream>
using namespace std;
int main(){
    int n, lastAlive, prevLastAlive;
    cin >> n;
    bool numbers[n];
    for(int i = 0; i < n; i++){
        numbers[i] = true;
    }
    for(int skip = 2; true; skip++){
        int skipped;
        skipped = 0;
        for(int i = 1; i < n; i++){
            if(numbers[i]){
                if(skipped % skip == 0){
                    lastAlive = i;
                }else{
                    numbers[i] = false;
                }
                skipped++;
            }
        }
        if(lastAlive == 1){
            cout << prevLastAlive;
            return 0;
        }else{
            prevLastAlive = lastAlive;
        }
    }
    return 0;
}
