#include <stdio.h>
int main(int argc, char const *argv[]) {
  int i, n;

  scanf("%d", &n);

  for (i = 3; i <= n; i++) {
    if (i % 3 == 0) {
      printf(" %d", i);
    } else {
      int temp = i;
      do {
        if (temp % 10 == 3) {
          printf(" %d", i);
          break;
        }
        temp /= 10;
      } while (temp > 0);
    }
  }
  puts("");
  return 0;
}
#include<iostream>
using namespace std;

int i = 1, x, n;

void checknum();
void include3();
void endchecknum();

int main() {
	cin >> n;
	checknum();
	return 0;
}

void checknum() {
	x = i;
	if (x % 3 == 0) {
		cout << " " << i;
		endchecknum();
	} else {
		include3();
	}
}

void include3() {
	if (x % 10 == 3) {
		cout << " " << i;
		endchecknum();
	} else {
		x /= 10;
		if (x) {
			include3();
		} else {
			endchecknum();
		}
	}
}

void endchecknum() {
	if (++i <= n) {
		checknum();
	} else {
		cout << endl;
		return;
	}
}