#include <iostream>
using namespace std;

int main()
{
    int mas[100000], n, num=2, max_el, prev_el, i, j;
    cin>>n;
    for(int i=0; i<n; i++){
        mas[i]=i+1;
    }
    max_el=n;
    while(max_el!=1){
        if(max_el!=1) prev_el=max_el;
        j=0;
        for(i=1; i<=n/num; i++){
            mas[i]=mas[j];
            j+=num;
            max_el=mas[i];
        }
        num++;
    }
    cout<<prev_el<<endl;
    return 0;
}
