#include<iostream>
using namespace std;
int main ()
{
    long long n, arr[1000], help[100][100]={}, k=2, p=0;
    cin >> n;
    for (int i=0; i<n; i++)
    {
        arr[i]=i+1;
        help[0][i]=arr[i];
    }
    for (int j=1; j<n; j++)
    {
        p=0;
        for (int i=0; i<n; i+=k)
        {
            help[j][p]=help[j-1][i];
            p++;
        }
        k++;
        if (help[j][1]==0)
        {
            p=j-1;
            break;
        }
    }
    int m=0;
    while (help[p][m]!=0)
    {
        m++;
    }
    cout << help[p][m-1] << endl;
    return 0;
}