#include <iostream>
using namespace std;

int main(){
    int n;
    cin>>n;
    int bigolg=n;
    int multiple=1;
    bool end=false;
    for(int j = 2; end!=true; j++){
        multiple*=j;
        for(int i=1; i<=bigolg+multiple; i+=multiple){
            //cout<<i<<" ";
            if(i>bigolg){
                if(i-multiple!=1){
                    bigolg=i-multiple;
                }else{
                    end=true;
                }
            }
        }
        //cout<<endl;
    }
    cout<<endl<<bigolg;
}
