#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main()
{
  int n = 0;
  fscanf(stdin, "%d", &n);
  for (int i = 1; i <= n; ++i) {
    if (i % 3 == 0) {
      fprintf(stdout, " %d", i);
    }
    else {
      for (int x = i; x > 0; x /= 10) {
        if (x % 10 == 3) {
          fprintf(stdout, " %d", i);
          break;
        }
      }
    }
  }
  fprintf(stdout, "\n");
  return 0;
}
#include <iostream>
#include <math.h>

using namespace std;

int main() {

	int n;
	cin >> n;

	for (int i = 1; i <= n;i++) {

		if (i % 3 == 0) {
			cout << " " << i;
		}
		else {
			
			for (int j = 0; j < 4;j++) {

				int n;
				int m;

				n = pow(10, j + 1);
				m = n / 10;

				if (j == 0 && i % n == 3) {
					cout << " " << i;
					break;
				}else if (j != 0 && (i % n) / m == 3) {
					cout << " " << i;
					break;
				}
			}

		}
	}

	cout << endl;

	//cin >> /*変数他*/;
	//cout << /*文字列*/ << endl;
	return 0;
}
