#include <iostream>
using namespace std;

int main(){
    int n=0;
    cin >> n;
    for(int i=1,x=i; i<=n; ++i,x=i){
        if(x%3==0) cout << " " << i;
        else while(x) if(x%10==3){ cout << " " << i; break; }else x/=10;
    }
    cout << endl;
}
