#include <iostream>
using namespace std;

bool div_ok(int n) {
  if (n % 3 == 0) {
    return true;
  } else {
    return false;
  }
}

bool num_dispear(int n) {
  while (n > 0) {
    if (n % 10 == 3) {
      return true;
    }
    n /= 10;
  }
  return false;
}

int main () {
  bool loop = true;
  int i = 1;
  int n;
  cin >> n;
  bool div_check = false;
  while (i <= n) {
    if (div_ok(i)) {
      cout << " " << i;
      div_check = true;
    }
    if (!div_check && num_dispear(i)) {
      cout << " " << i;
    }
    i++;
    div_check = false;
  }
  cout << endl;
  return 0;
}
#include<bits/stdc++.h>
#include<sstream>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

void call(int n){
  for(int i=1;i<=n;i++){
    stringstream ss;
    ss<<i;
    char c[8];
    ss>>c;
    if(i%3==0||strstr(c,"3"))
      cout<<" "<<i;
  }
  cout<<endl;
}

int main(){ _;
  int n;cin>>n;
  call(n);
}