#include<iostream>

using namespace std;

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

	return 0;
}
