#include<iostream>
using namespace std;

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

	return 0;
}