#include <iostream>
using namespace std;

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