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