import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		InputStreamReader insISR = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(insISR);
		int intA = 1;
	//	System.out.println("????????\????????????????????????");
		try {
			String strLine = reader.readLine();
			int intNum = Integer.parseInt(strLine);
			int intYakusuu = 0;
			int intThreetimes = 3;
			String strCheckNum = "3";
			intYakusuu = intNum % intThreetimes;
			while(intA <= intNum) {
				String strA = String.valueOf(intA);
				boolean isOk1 = false;
				boolean isOk2 = false;
				intYakusuu = intA % intThreetimes;
				int intYakusuu1 = intA % 10;
				if(intYakusuu == 0) {
					System.out.print(" "+intA);
					intThreetimes = intThreetimes + 3;
					isOk1 = true;
				}
				else if(intYakusuu1 == 3) {
					System.out.print(" "+intA);
					isOk2 = true;
				}
				else if(strA.indexOf(strCheckNum) != -1) {
					System.out.print(" "+strA);
				}
				intA = intA + 1;
			}
			System.out.println("");
		}catch(IOException e) {
			System.out.println(e);
		}catch(NumberFormatException e) {
			System.out.println(e);
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) {
		InputStreamReader insISR = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(insISR);
		int intA = 1;
	//	System.out.println("????????\????????????????????????");
		try {
			String strLine = reader.readLine();
			int intNum = Integer.parseInt(strLine);
			int intYakusuu = 0;
			int intThreetimes = 3;
			String strCheckNum = "3";
			intYakusuu = intNum % intThreetimes;
			while(intA <= intNum) {
				String strA = String.valueOf(intA);
				boolean isOk1 = false;
				boolean isOk2 = false;
				intYakusuu = intA % intThreetimes;
				int intYakusuu1 = intA % 10;
				if(intYakusuu == 0) {
					System.out.print(" "+intA);
					intThreetimes = intThreetimes + 3;
					isOk1 = true;
				}
				else if(intYakusuu1 == 3) {
					System.out.print(" "+intA);
					isOk2 = true;
				}
				else if(strA.indexOf(strCheckNum) != -1) {
					System.out.print(" "+strA);
				}
				intA = intA + 1;
			}
			System.out.println("");
		}catch(IOException e) {
			System.out.println(e);
		}catch(NumberFormatException e) {
			System.out.println(e);
		}
	}
} Main public static void main(String[] args) {
		InputStreamReader insISR = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(insISR);
		int intA = 1;
	//	System.out.println("????????\????????????????????????");
		try {
			String strLine = reader.readLine();
			int intNum = Integer.parseInt(strLine);
			int intYakusuu = 0;
			int intThreetimes = 3;
			String strCheckNum = "3";
			intYakusuu = intNum % intThreetimes;
			while(intA <= intNum) {
				String strA = String.valueOf(intA);
				boolean isOk1 = false;
				boolean isOk2 = false;
				intYakusuu = intA % intThreetimes;
				int intYakusuu1 = intA % 10;
				if(intYakusuu == 0) {
					System.out.print(" "+intA);
					intThreetimes = intThreetimes + 3;
					isOk1 = true;
				}
				else if(intYakusuu1 == 3) {
					System.out.print(" "+intA);
					isOk2 = true;
				}
				else if(strA.indexOf(strCheckNum) != -1) {
					System.out.print(" "+strA);
				}
				intA = intA + 1;
			}
			System.out.println("");
		}catch(IOException e) {
			System.out.println(e);
		}catch(NumberFormatException e) {
			System.out.println(e);
		}
	} main {
		InputStreamReader insISR = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(insISR);
		int intA = 1;
	//	System.out.println("????????\????????????????????????");
		try {
			String strLine = reader.readLine();
			int intNum = Integer.parseInt(strLine);
			int intYakusuu = 0;
			int intThreetimes = 3;
			String strCheckNum = "3";
			intYakusuu = intNum % intThreetimes;
			while(intA <= intNum) {
				String strA = String.valueOf(intA);
				boolean isOk1 = false;
				boolean isOk2 = false;
				intYakusuu = intA % intThreetimes;
				int intYakusuu1 = intA % 10;
				if(intYakusuu == 0) {
					System.out.print(" "+intA);
					intThreetimes = intThreetimes + 3;
					isOk1 = true;
				}
				else if(intYakusuu1 == 3) {
					System.out.print(" "+intA);
					isOk2 = true;
				}
				else if(strA.indexOf(strCheckNum) != -1) {
					System.out.print(" "+strA);
				}
				intA = intA + 1;
			}
			System.out.println("");
		}catch(IOException e) {
			System.out.println(e);
		}catch(NumberFormatException e) {
			System.out.println(e);
		}
	} InputStreamReader insISR = new InputStreamReader(System.in); insISR new InputStreamReader(System.in) BufferedReader reader = new BufferedReader(insISR); reader new BufferedReader(insISR) int intA = 1; intA 1 try {
			String strLine = reader.readLine();
			int intNum = Integer.parseInt(strLine);
			int intYakusuu = 0;
			int intThreetimes = 3;
			String strCheckNum = "3";
			intYakusuu = intNum % intThreetimes;
			while(intA <= intNum) {
				String strA = String.valueOf(intA);
				boolean isOk1 = false;
				boolean isOk2 = false;
				intYakusuu = intA % intThreetimes;
				int intYakusuu1 = intA % 10;
				if(intYakusuu == 0) {
					System.out.print(" "+intA);
					intThreetimes = intThreetimes + 3;
					isOk1 = true;
				}
				else if(intYakusuu1 == 3) {
					System.out.print(" "+intA);
					isOk2 = true;
				}
				else if(strA.indexOf(strCheckNum) != -1) {
					System.out.print(" "+strA);
				}
				intA = intA + 1;
			}
			System.out.println("");
		}catch(IOException e) {
			System.out.println(e);
		}catch(NumberFormatException e) {
			System.out.println(e);
		} catch(IOException e) {
			System.out.println(e);
		} IOException e {
			System.out.println(e);
		} System.out.println(e) System.out.println System.out System System.out e catch(NumberFormatException e) {
			System.out.println(e);
		} NumberFormatException e {
			System.out.println(e);
		} System.out.println(e) System.out.println System.out System System.out e {
			String strLine = reader.readLine();
			int intNum = Integer.parseInt(strLine);
			int intYakusuu = 0;
			int intThreetimes = 3;
			String strCheckNum = "3";
			intYakusuu = intNum % intThreetimes;
			while(intA <= intNum) {
				String strA = String.valueOf(intA);
				boolean isOk1 = false;
				boolean isOk2 = false;
				intYakusuu = intA % intThreetimes;
				int intYakusuu1 = intA % 10;
				if(intYakusuu == 0) {
					System.out.print(" "+intA);
					intThreetimes = intThreetimes + 3;
					isOk1 = true;
				}
				else if(intYakusuu1 == 3) {
					System.out.print(" "+intA);
					isOk2 = true;
				}
				else if(strA.indexOf(strCheckNum) != -1) {
					System.out.print(" "+strA);
				}
				intA = intA + 1;
			}
			System.out.println("");
		} String strLine = reader.readLine(); strLine reader.readLine() reader.readLine reader int intNum = Integer.parseInt(strLine); intNum Integer.parseInt(strLine) Integer.parseInt Integer strLine int intYakusuu = 0; intYakusuu 0 int intThreetimes = 3; intThreetimes 3 String strCheckNum = "3"; strCheckNum "3" intYakusuu = intNum % intThreetimes intYakusuu intNum % intThreetimes intNum intThreetimes while(intA <= intNum) {
				String strA = String.valueOf(intA);
				boolean isOk1 = false;
				boolean isOk2 = false;
				intYakusuu = intA % intThreetimes;
				int intYakusuu1 = intA % 10;
				if(intYakusuu == 0) {
					System.out.print(" "+intA);
					intThreetimes = intThreetimes + 3;
					isOk1 = true;
				}
				else if(intYakusuu1 == 3) {
					System.out.print(" "+intA);
					isOk2 = true;
				}
				else if(strA.indexOf(strCheckNum) != -1) {
					System.out.print(" "+strA);
				}
				intA = intA + 1;
			} intA <= intNum intA intNum {
				String strA = String.valueOf(intA);
				boolean isOk1 = false;
				boolean isOk2 = false;
				intYakusuu = intA % intThreetimes;
				int intYakusuu1 = intA % 10;
				if(intYakusuu == 0) {
					System.out.print(" "+intA);
					intThreetimes = intThreetimes + 3;
					isOk1 = true;
				}
				else if(intYakusuu1 == 3) {
					System.out.print(" "+intA);
					isOk2 = true;
				}
				else if(strA.indexOf(strCheckNum) != -1) {
					System.out.print(" "+strA);
				}
				intA = intA + 1;
			} String strA = String.valueOf(intA); strA String.valueOf(intA) String.valueOf String intA boolean isOk1 = false; isOk1 false boolean isOk2 = false; isOk2 false intYakusuu = intA % intThreetimes intYakusuu intA % intThreetimes intA intThreetimes int intYakusuu1 = intA % 10; intYakusuu1 intA % 10 intA 10 if(intYakusuu == 0) {
					System.out.print(" "+intA);
					intThreetimes = intThreetimes + 3;
					isOk1 = true;
				}
				else if(intYakusuu1 == 3) {
					System.out.print(" "+intA);
					isOk2 = true;
				}
				else if(strA.indexOf(strCheckNum) != -1) {
					System.out.print(" "+strA);
				} intYakusuu == 0 intYakusuu 0 {
					System.out.print(" "+intA);
					intThreetimes = intThreetimes + 3;
					isOk1 = true;
				} System.out.print(" "+intA) System.out.print System.out System System.out " "+intA " " intA intThreetimes = intThreetimes + 3 intThreetimes intThreetimes + 3 intThreetimes 3 isOk1 = true isOk1 true if(intYakusuu1 == 3) {
					System.out.print(" "+intA);
					isOk2 = true;
				}
				else if(strA.indexOf(strCheckNum) != -1) {
					System.out.print(" "+strA);
				} intYakusuu1 == 3 intYakusuu1 3 {
					System.out.print(" "+intA);
					isOk2 = true;
				} System.out.print(" "+intA) System.out.print System.out System System.out " "+intA " " intA isOk2 = true isOk2 true if(strA.indexOf(strCheckNum) != -1) {
					System.out.print(" "+strA);
				} strA.indexOf(strCheckNum) != -1 strA.indexOf(strCheckNum) strA.indexOf strA strCheckNum -1 1 {
					System.out.print(" "+strA);
				} System.out.print(" "+strA) System.out.print System.out System System.out " "+strA " " strA intA = intA + 1 intA intA + 1 intA 1 System.out.println("") System.out.println System.out System System.out "" String[] args args public class Main {
	public static void main(String[] args) {
		InputStreamReader insISR = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(insISR);
		int intA = 1;
	//	System.out.println("????????\????????????????????????");
		try {
			String strLine = reader.readLine();
			int intNum = Integer.parseInt(strLine);
			int intYakusuu = 0;
			int intThreetimes = 3;
			String strCheckNum = "3";
			intYakusuu = intNum % intThreetimes;
			while(intA <= intNum) {
				String strA = String.valueOf(intA);
				boolean isOk1 = false;
				boolean isOk2 = false;
				intYakusuu = intA % intThreetimes;
				int intYakusuu1 = intA % 10;
				if(intYakusuu == 0) {
					System.out.print(" "+intA);
					intThreetimes = intThreetimes + 3;
					isOk1 = true;
				}
				else if(intYakusuu1 == 3) {
					System.out.print(" "+intA);
					isOk2 = true;
				}
				else if(strA.indexOf(strCheckNum) != -1) {
					System.out.print(" "+strA);
				}
				intA = intA + 1;
			}
			System.out.println("");
		}catch(IOException e) {
			System.out.println(e);
		}catch(NumberFormatException e) {
			System.out.println(e);
		}
	}
} public class Main {
	public static void main(String[] args) {
		InputStreamReader insISR = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(insISR);
		int intA = 1;
	//	System.out.println("????????\????????????????????????");
		try {
			String strLine = reader.readLine();
			int intNum = Integer.parseInt(strLine);
			int intYakusuu = 0;
			int intThreetimes = 3;
			String strCheckNum = "3";
			intYakusuu = intNum % intThreetimes;
			while(intA <= intNum) {
				String strA = String.valueOf(intA);
				boolean isOk1 = false;
				boolean isOk2 = false;
				intYakusuu = intA % intThreetimes;
				int intYakusuu1 = intA % 10;
				if(intYakusuu == 0) {
					System.out.print(" "+intA);
					intThreetimes = intThreetimes + 3;
					isOk1 = true;
				}
				else if(intYakusuu1 == 3) {
					System.out.print(" "+intA);
					isOk2 = true;
				}
				else if(strA.indexOf(strCheckNum) != -1) {
					System.out.print(" "+strA);
				}
				intA = intA + 1;
			}
			System.out.println("");
		}catch(IOException e) {
			System.out.println(e);
		}catch(NumberFormatException e) {
			System.out.println(e);
		}
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		InputStreamReader insISR = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(insISR);
		int intA = 1;
	//	System.out.println("????????\????????????????????????");
		try {
			String strLine = reader.readLine();
			int intNum = Integer.parseInt(strLine);
			int intYakusuu = 0;
			int intThreetimes = 3;
			String strCheckNum = "3";
			intYakusuu = intNum % intThreetimes;
			while(intA <= intNum) {
				String strA = String.valueOf(intA);
				boolean isOk1 = false;
				boolean isOk2 = false;
				intYakusuu = intA % intThreetimes;
				int intYakusuu1 = intA % 10;
				if(intYakusuu == 0) {
					System.out.print(" "+intA);
					intThreetimes = intThreetimes + 3;
					isOk1 = true;
				}
				else if(intYakusuu1 == 3) {
					System.out.print(" "+intA);
					isOk2 = true;
				}
				else if(strA.indexOf(strCheckNum) != -1) {
					System.out.print(" "+strA);
				}
				intA = intA + 1;
			}
			System.out.println("");
		}catch(IOException e) {
			System.out.println(e);
		}catch(NumberFormatException e) {
			System.out.println(e);
		}
	}
}