#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>
using namespace std;

int main(int argc,char* argv[]){
  int input,num,tmp;num=1;cin >> input;
  while(num<=input){
    if(num%3==0){cout<<" "<<num;num++;}
    if(num>input) break;tmp=num;
    while(tmp!=0){if(tmp%10==3){ cout<<" "<<num;break;}tmp/=10;}
    num++;}
  cout<<endl;}