#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

void call(int n){
	for(int i = 1; i <= n; i++){
		if(i % 3 == 0) cout << " " << i;
		else{
			for(int tmp = i; tmp != 0; tmp /= 10){
				if(tmp % 10 == 3){
					cout << " " << i;
					break;
				}
			}
		}
	}
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	call(n);
	return 0;
}
#include<iostream>
using namespace std;

int x, i = 1;
int n;

void check_num();
void include3();
void end_check_num();

void check_num() {
	x = i;
	if (x % 3 == 0){
		cout << " " << i;
		end_check_num();
	}else include3();
}

void include3() {
	if (x % 10 == 3){
		cout << " " << i;
		end_check_num();
	}else{
		x /= 10;
		if (x)include3();
		else end_check_num();
	}
}

void end_check_num() {
	if (++i <= n) check_num();
}


int main() {
	cin >> n;
	check_num();
	cout << endl;
	char c;
	cin >> c;
}