#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n, copyN;
    cin>>n;
    copyN = n;
    int i = 1;
    while(n != 1)
    {
        i++;
        long long chastno, ost;
        chastno = n / i;
        ost = n % i;
        if(ost != 0) chastno++;
        n = chastno;
        ///cout<<i<<" "<<n<<endl;
    }
    long long m = 1;
    for(int j = 2; j < i; j++)
    {
        m*=j;
    }
    long long k = 1;
    while(true)
    {
        if(k+m <= copyN) k+=m;
        else break;
    }
    cout<<k<<endl;
    return 0;
}
