#include <iostream>
using namespace std;
int main ()
{
    string b;
    string a;
    int N;
    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        a+= i;
    }
    int l;
    int k = 2;
    int ng;
    do
    {
        l = a.length();
        ng = a[l-1];
        for (int i = 0 ; i < l; i+=k)
        {
            b+=a[i];
        }
        l = b.length();
        if (l == 1)
        {
            cout << ng << endl;
            return 0;
        }
        ng = b[l-1];
        a ="";
        k++;
        for (int i = 0; i < l; i+=k)
        {
            a+=b[i];
        }
        l = a.length();
        if (l == 1)
        {
            cout << ng << endl;
            return 0;
        }
        b="";
        k++;
    }
    while (l != 1);
}
