import std.stdio, std.string, std.conv;
void main() {
	int n = readln.chomp.to!int;
	int flg = 1;
	int i = 1;
	int x;
	while(flg > 0) {
		if (flg == 1) {
			x = i;
			if (x % 3 == 0) {
				" %d".writef(i);
				flg = 3;
				continue;
			}
			flg = 2;
			continue;
		}

		if (flg == 2) {
			if (x % 10 == 3) {
				" %d".writef(i);
				flg = 3;
				continue;
			}
			x /= 10;
			if (x != 0) {
				flg = 2;
				continue;
			}

			flg = 3;
			continue;
		}

		if (flg == 3) {
			if (++i <= n) {
				flg = 1;
				continue;
			}
			"".writeln;
			break;
		}
	}
}