/***************************************************************************\
                           __    ______   ____    ____
                          |  |  /  __  \  \   \  /   /                      |
                          |  | |  |  |  |  \   \/   /                       |
                    .--.  |  | |  |  |  |   \_    _/                        |
                    |  `--'  | |  '--'  |     |  |                          |
                     \______/   \______/      |__|                          |
                                                                            |
            Codeforces = Joy     ||     CodeChef = jubayer_joy              |
            Mail = joy.cse5.bu@gmail.com || jubayerjoy98@gmail.com          |
            CSE, University of Barisal (18CSE040)                           |
                                                                            |
/***************************************************************************/


#pragma GCC optimize("O3")

#include<bits/stdc++.h>

using namespace std;

using       ll      =       long long   ;
using       ld      =       long double ;
using       vi      =       vector<int> ;
using       vll     =       vector<ll>  ;
using       pll     =       pair<ll,ll> ;
using       pii     =       pair<int, int>;

const double pi     =       acos(-1.0)  ;

#define     spc             " "
#define     el              "\n"
#define     die             return 0
#define     ios             ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define     pb              push_back
#define     pf              push_front
#define     bitcount        __builtin_popcount
#define     gcd(a,b)        __gcd(a,b)
#define     lcm(a,b)        (a) * ((b) / gcd(a,b))
#define     max3(a,b,c)     max((a), max((b),(c)))
#define     max4(a,b,c,d)   max((d),max3(a,b,c))
#define     min3(a,b,c)     min((a), min((b),(c)))
#define     min4(a,b,c,d)   min((d),min3(a,b,c))
#define     fr(i,a,b)       for(ll i = (a); i<=(b); i++)
#define     f(i,n)          for(ll i =0; i<(n); i++)
#define     SUM(a)          accumulate(a.begin(), a.end(), 0)
#define     Product(a)      accumulate(a.begin(), a.end(), 1, multiplies<int>())
#define     ff              first
#define     ss              second
#define     all(v)          v.begin(), v.end()
#define     Sort(v)         sort(all(v))
#define     rev(v)          reverse(all(v))
#define     rsort(v)        {Sort(v); rev(v);}
#define     Y()             cout<<"Yes\n"
#define     y()             cout<<"yes\n"
#define     N()             cout<<"No\n"
#define     n()             cout<<"no\n"
#define     in(a)          scanf("%d",&a);
#define     in2(a,b)        scanf("%d %d",&a,&b);

//cout << fixed << setprecision(20)<< value <<endl;
//greater <int>

//Debugging
#define     Read()          freopen("input.txt","r",stdin)
#define     D(x)            cerr << __LINE__ << ": " << #x << " = " << x << el;
#define     D2(x,y)         cerr << __LINE__ << ": " << #x << " = " << x << "\t\t" << #y << " = " << y << el;
#define     D3(x,y,z)       cerr << __LINE__ << ": " << #x << " = " << x << "\t\t" << #y << " = " << y << "\t\t" << #z << " = " << z <<el


//const int fx[]={+1,-1,+0,+0};             // Four Direction
//const int fy[]={+0,+0,+1,-1};             // Four Direction
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move - 8 Direction
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move - 8 Direction
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move

int n, i = 1;

int main(int argc, char const *argv[])
{
    int n;
    cin>>n;

    while(1)
    {
        int x =i;
        bool f= 0;
        //D3(x,i, f);
        if(x%3 ==0){
            cout<<spc<<i;
            f= 1;
        }
        while(x&&f==0){
            if(x%10==3){
                cout<<spc<<i;
                break;
            }
            x/=10;
        }
        if(++i >n)
            break;
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 3100