#include using namespace std; int main() { int n,b=0,c=0; cin >> n; for(int i = 1;i <= n;i++) { b = i; while(b >= 1) { c = b % 10; b = b / 10; if(i % 3 == 0 && c == 5) { cout << i << endl; break; } } } return 0; }