#include<bits/stdc++.h>
using namespace std;
int main()
{
int n=101;
while(1){
	if(n%3==2&&n%5==3&&n%7==5){
		cout<<n<<endl;
		break;
	}
	n++;
}
return 0;
}

/**************************************************************
	Problem: 1055
	User: zzz1
	Language: C++
	Result: Wrong Answer
****************************************************************/