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

/**************************************************************
	Problem: 1017
	User: tangkaixuan
	Language: C++
	Result: Accepted
	Time:4 ms
	Memory:2072 kb
****************************************************************/