#include<iostream>
using namespace std;

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