#include<bits/stdc++.h>
using namespace std;
int main(){
    int a=100;
    while(a<1000){
    	if(a%3==2&&a%5==3&&a%7==5){
			printf("%d",a);
    		break;
		}
		a++;
	}
	
}
/**************************************************************
	Problem: 1017
	User: toughuatao1
	Language: C++
	Result: Accepted
	Time:10 ms
	Memory:2072 kb
****************************************************************/