#include<stdio.h>
#include<string.h>
int main(void) {
	int a[10000],n,b=0,i,x,d=3;
	char r[10000];
	char s[10000];
	scanf("%d", &n);
	sprintf(s, "%d", d);
	for(i = 1; i <= n; i++) {
		sprintf(r,"%d", i);
		if (i % 3 == 0) {
			a[b] = i;
			b++;
		}
		else if (strstr(r,s) != NULL) {
			a[b] = i;
			b++;
	}

	}
	for (x = 0; x < b; x++) {
		if (x == 0) {
			printf(" ");
	}
		printf("%d",a[x]);
		if (x == b - 1) {
			printf("\n");
		}
		else {
			printf(" ");
		}
	}
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

void call(int n) {
	int i = 1;
	int x;
	bool flg = false;
	while (1) {
		// CHECK_NUM
		x = i;
		if ( x % 3 == 0 ){
			cout << " " << i;
		}
		else {
			while (1) {
				// INCLUDE3
				if ( x % 10 == 3 ){
					cout << " " << i;
					flg = true;
				}
				else {
					x /= 10;
					if ( x ) {
						continue;
					}
					else {
						flg = true;
					}
				}
				if (flg == true) {
					break;
				}
			}
		}
		flg = false;
		// END_CHECK_NUM
		if ( ++i <= n ) {
			continue;
		}
		else {
			cout << endl;
			break;
		}
	}
}

int main(void)
{
	int n;
	cin >> n;
	call(n);
	return 0;
}
