#include <iostream>

using namespace std;

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

