#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0;i < N;i++)
    {
        a[i] = i + 1;
    }
    vector<int> b;
    int k = 2;
    int c;
    while(a.size() != 1)
    {
        c = a.back();
        for(int i = 0;i < a.size();i++)
        {
            if(i % k == 0)
            {
                b.push_back(a[i]);
            }
        }
        while(a.size() > b.size())
        {
            a.pop_back();
        }
        for(int i = 0;i < b.size();i++)
        {
            a[i] = b[i];
        }
        while(b.size() > 0)
        {
            b.pop_back();
        }
        k++;
    }
    cout << c << endl;
    return 0;
}
