#include<bits/stdc++.h>
using namespace std;
int main(){
	for(int x = 101;; ++x) {
		if(x % 3 == 2 && x % 5 == 3 && x % 7 == 5){
			cout<<x<<endl;
			break;
		}
	}
	return 0;
}
/**************************************************************
	Problem: 1017
	User: linyuhang
	Language: C++
	Result: Accepted
	Time:7 ms
	Memory:2072 kb
****************************************************************/