#include <iostream>
using namespace std;

bool hasDigitFive(int num) {
    while (num > 0) {
        if (num % 10 == 5) {
            return true;
        }
        num /= 10;
    }
    return false;
}

int main() {
    for (int i = 1; i <= 999; i++) {
        if (i % 3 == 0 && hasDigitFive(i)) {
            cout << i << endl;
        }
    }
    return 0;
}    
/**************************************************************
	Problem: 1059
	User: linmiaoling
	Language: C++
	Result: Accepted
	Time:6 ms
	Memory:2072 kb
****************************************************************/