#include <bits/stdc++.h>
using namespace std;

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

