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

    }
    while (l != 1);
}
