#include <bits/stdc++.h>
using namespace std;
bool isincluded (int p){
    if(p%10==3)return true;
    else p/=10;
    if(p==0){return false;}
return isincluded(p);
}
int main() {
int n;
cin >> n;
for(int i=1;i<n+1;i++){
    if(isincluded(i) || i%3==0)cout << " " << i;
}
cout << endl;
}

