#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>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;

void call(int n) {
	int i = 1;
	do {
		int x = i;
		bool END_CHECK_NUM = false;
		if (x % 3 == 0) {
			cout << " " << i;
			END_CHECK_NUM = true;
		}
		do {
			if (!END_CHECK_NUM && x % 10 == 3) {
				cout << " " << i;
				END_CHECK_NUM = true;
			}
			x /= 10;
		} while (!END_CHECK_NUM && x);
	} while (++i <= n);

	cout << endl;
}

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