#include<bits/stdc++.h>
using namespace std;
int main(){
	int n = 999,x = 1,a,b,c,cnt;
    while(x<=n)
    {
        a = x/100;
        b = (x/10)%10;
        c = x%10;
        if((x % 3 == 0)&& (a == 5 || b == 5 || c == 5))
        {
            cout << x << endl;
            cnt++;
        }
        x++;
         
    }
	return 0;
}
/**************************************************************
	Problem: 1059
	User: fuhoubin
	Language: C++
	Result: Accepted
	Time:13 ms
	Memory:2072 kb
****************************************************************/