#include <iostream>
using namespace std;

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