#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;
}
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    for (int i=3;i<=n;i++) {
        int x=i;
        if (i%3==0 || i%10==3) {
            printf(" %d",i);
        } else {
            while (x>0) {
                if (x%10==3) {
                    printf(" %d",i);
                    break;
                }
                x/=10;
            }
        }
    }
    printf("\n");
    return 0;
}

