'use strict'

const main = arg => {
    const include3 = (num, origin) => {
        let divide = parseInt(num / 10, 10);
        if( divide ){
            if(divide % 10 === 3){
                return origin;
            }
            return include3(divide, origin);
        } else {
            return 0;
        }
    }

    const input = parseInt(arg.trim().split("\n"), 10);
    //3の倍数を取得
    //10の倍数を取得。 10以上かも確認
    const result = [];
    [...Array(input)].forEach((obj, i) => {
        const num = i+1;
        if(num % 3 === 0){
            result.push(num);
        } else if(num % 10 === 3){
            result.push(num);
        } else {
            const cb = include3(num, num);
            if(cb !== 0){
                result.push(cb);
            }
        }
    });

    console.log(" "+result.join(" "));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
