#include<iostream> using namespace std; int main(){ int a; cin>>a; for(long long b=a+1;;b++){ if(b%3==2&&b%5==3&&b%7==2){ cout<<b; return 0; } } }