#include<bits/stdc++.h>
#include<sstream>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

void call(int n){
  for(int i=1;i<=n;i++){
    stringstream ss;
    ss<<i;
    char c[8];
    ss>>c;
    if(i%3==0||strstr(c,"3"))
      cout<<" "<<i;
  }
  cout<<endl;
}

int main(){ _;
  int n;cin>>n;
  call(n);
}
#include <iostream>

using namespace std;

void call(int num) {

	for (int i = 1; i <= num; i++) {

		int x = i;

		//3????????°?????¨???
		if (x % 3 == 0) {
			cout << " " << i;
		}
		//3???????????°?????¨???
		else {
			do {

				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}

				x/= 10;

			} while (x);

		}
	}

	cout << endl;

}

int main(){

	int num;

	cin >> num;

	call(num);
	
	return 0;
}