#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;


int main(){
    int n;
    cin >> n;
    if(n < 3 || n > 10000) return -1;
    for(int i = 1 ;i <= n ; i ++){
        int x = i;
        if(x % 3 == 0){
            cout << " " << i ;
            continue;
        }else if(x % 10 == 3){
            cout << " " << i ;
            continue;
        }else{
            while(x > 0){
                x = round(x/10);
                if(x % 10 == 3){
                    cout << " " << i ;
                    break;
                }
            }
            continue;
        }
    }
    cout << endl;

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int main (){
    string s;
    cin >> s;

    s = s.substr(0, s.size()-8);

    cout << s << endl;

    return 0;
}