import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

// void call(int n){
//   int i = 1;
//  CHECK_NUM:
//   int x = i;
//   if ( x % 3 == 0 ){
//     cout << " " << i;
//     goto END_CHECK_NUM;
//   }
//  INCLUDE3:
//   if ( x % 10 == 3 ){
//     cout << " " << i;
//     goto END_CHECK_NUM;
//   }
//   x /= 10;
//   if ( x ) goto INCLUDE3;
//  END_CHECK_NUM:
//   if ( ++i <= n ) goto CHECK_NUM;
//
//   cout << endl;
// }

public class Main{

    static StringBuilder sb;

    public static void main(String[] args) {
	try {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    List<String> lines = new ArrayList<String>();

	    for (String line = br.readLine(); line != null; line = br.readLine()) {
		lines.add(line);
	    }
	    //lines.add("60");
	    br.close();

	    Integer n = Integer.parseInt(lines.get(0));
	    sb = new StringBuilder();

	    for (int i = 1; i <= n; i++) {
		if (i%3==0) {
		    sb.append(" " + i);
		} else if (i%10==3) {
		    sb.append(" " + i);
		} else if (String.valueOf(i).contains("3")) {
		    sb.append(" " + i);
		}
	    }
	    System.out.println(sb.toString());
	    System.exit(0);

	} catch (Exception e) {
	    System.out.println(e.getMessage());
	    System.out.println(Arrays.toString(e.getStackTrace()));
	    System.exit(0);
	}
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Arrays; Arrays java.util import java.util.List; List java.util import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.Comparator; Comparator java.util public class Main{

    static StringBuilder sb;

    public static void main(String[] args) {
	try {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    List<String> lines = new ArrayList<String>();

	    for (String line = br.readLine(); line != null; line = br.readLine()) {
		lines.add(line);
	    }
	    //lines.add("60");
	    br.close();

	    Integer n = Integer.parseInt(lines.get(0));
	    sb = new StringBuilder();

	    for (int i = 1; i <= n; i++) {
		if (i%3==0) {
		    sb.append(" " + i);
		} else if (i%10==3) {
		    sb.append(" " + i);
		} else if (String.valueOf(i).contains("3")) {
		    sb.append(" " + i);
		}
	    }
	    System.out.println(sb.toString());
	    System.exit(0);

	} catch (Exception e) {
	    System.out.println(e.getMessage());
	    System.out.println(Arrays.toString(e.getStackTrace()));
	    System.exit(0);
	}
    }
} Main static StringBuilder sb; sb public static void main(String[] args) {
	try {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    List<String> lines = new ArrayList<String>();

	    for (String line = br.readLine(); line != null; line = br.readLine()) {
		lines.add(line);
	    }
	    //lines.add("60");
	    br.close();

	    Integer n = Integer.parseInt(lines.get(0));
	    sb = new StringBuilder();

	    for (int i = 1; i <= n; i++) {
		if (i%3==0) {
		    sb.append(" " + i);
		} else if (i%10==3) {
		    sb.append(" " + i);
		} else if (String.valueOf(i).contains("3")) {
		    sb.append(" " + i);
		}
	    }
	    System.out.println(sb.toString());
	    System.exit(0);

	} catch (Exception e) {
	    System.out.println(e.getMessage());
	    System.out.println(Arrays.toString(e.getStackTrace()));
	    System.exit(0);
	}
    } main {
	try {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    List<String> lines = new ArrayList<String>();

	    for (String line = br.readLine(); line != null; line = br.readLine()) {
		lines.add(line);
	    }
	    //lines.add("60");
	    br.close();

	    Integer n = Integer.parseInt(lines.get(0));
	    sb = new StringBuilder();

	    for (int i = 1; i <= n; i++) {
		if (i%3==0) {
		    sb.append(" " + i);
		} else if (i%10==3) {
		    sb.append(" " + i);
		} else if (String.valueOf(i).contains("3")) {
		    sb.append(" " + i);
		}
	    }
	    System.out.println(sb.toString());
	    System.exit(0);

	} catch (Exception e) {
	    System.out.println(e.getMessage());
	    System.out.println(Arrays.toString(e.getStackTrace()));
	    System.exit(0);
	}
    } try {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    List<String> lines = new ArrayList<String>();

	    for (String line = br.readLine(); line != null; line = br.readLine()) {
		lines.add(line);
	    }
	    //lines.add("60");
	    br.close();

	    Integer n = Integer.parseInt(lines.get(0));
	    sb = new StringBuilder();

	    for (int i = 1; i <= n; i++) {
		if (i%3==0) {
		    sb.append(" " + i);
		} else if (i%10==3) {
		    sb.append(" " + i);
		} else if (String.valueOf(i).contains("3")) {
		    sb.append(" " + i);
		}
	    }
	    System.out.println(sb.toString());
	    System.exit(0);

	} catch (Exception e) {
	    System.out.println(e.getMessage());
	    System.out.println(Arrays.toString(e.getStackTrace()));
	    System.exit(0);
	} catch (Exception e) {
	    System.out.println(e.getMessage());
	    System.out.println(Arrays.toString(e.getStackTrace()));
	    System.exit(0);
	} Exception e {
	    System.out.println(e.getMessage());
	    System.out.println(Arrays.toString(e.getStackTrace()));
	    System.exit(0);
	} System.out.println(e.getMessage()) System.out.println System.out System System.out e.getMessage() e.getMessage e System.out.println(Arrays.toString(e.getStackTrace())) System.out.println System.out System System.out Arrays.toString(e.getStackTrace()) Arrays.toString Arrays e.getStackTrace() e.getStackTrace e System.exit(0) System.exit System 0 {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    List<String> lines = new ArrayList<String>();

	    for (String line = br.readLine(); line != null; line = br.readLine()) {
		lines.add(line);
	    }
	    //lines.add("60");
	    br.close();

	    Integer n = Integer.parseInt(lines.get(0));
	    sb = new StringBuilder();

	    for (int i = 1; i <= n; i++) {
		if (i%3==0) {
		    sb.append(" " + i);
		} else if (i%10==3) {
		    sb.append(" " + i);
		} else if (String.valueOf(i).contains("3")) {
		    sb.append(" " + i);
		}
	    }
	    System.out.println(sb.toString());
	    System.exit(0);

	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) List<String> lines = new ArrayList<String>(); lines new ArrayList<String>() for (String line = br.readLine(); line != null; line = br.readLine()) {
		lines.add(line);
	    } String line = br.readLine(); String line = br.readLine(); line br.readLine() br.readLine br line != null line null line = br.readLine() line = br.readLine() line br.readLine() br.readLine br {
		lines.add(line);
	    } {
		lines.add(line);
	    } lines.add(line) lines.add lines line br.close() br.close br Integer n = Integer.parseInt(lines.get(0)); n Integer.parseInt(lines.get(0)) Integer.parseInt Integer lines.get(0) lines.get lines 0 sb = new StringBuilder() sb new StringBuilder() for (int i = 1; i <= n; i++) {
		if (i%3==0) {
		    sb.append(" " + i);
		} else if (i%10==3) {
		    sb.append(" " + i);
		} else if (String.valueOf(i).contains("3")) {
		    sb.append(" " + i);
		}
	    } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
		if (i%3==0) {
		    sb.append(" " + i);
		} else if (i%10==3) {
		    sb.append(" " + i);
		} else if (String.valueOf(i).contains("3")) {
		    sb.append(" " + i);
		}
	    } {
		if (i%3==0) {
		    sb.append(" " + i);
		} else if (i%10==3) {
		    sb.append(" " + i);
		} else if (String.valueOf(i).contains("3")) {
		    sb.append(" " + i);
		}
	    } if (i%3==0) {
		    sb.append(" " + i);
		} else if (i%10==3) {
		    sb.append(" " + i);
		} else if (String.valueOf(i).contains("3")) {
		    sb.append(" " + i);
		} i%3==0 i%3 i 3 0 {
		    sb.append(" " + i);
		} sb.append(" " + i) sb.append sb " " + i " " i if (i%10==3) {
		    sb.append(" " + i);
		} else if (String.valueOf(i).contains("3")) {
		    sb.append(" " + i);
		} i%10==3 i%10 i 10 3 {
		    sb.append(" " + i);
		} sb.append(" " + i) sb.append sb " " + i " " i if (String.valueOf(i).contains("3")) {
		    sb.append(" " + i);
		} String.valueOf(i).contains("3") String.valueOf(i).contains String.valueOf(i) String.valueOf String i "3" {
		    sb.append(" " + i);
		} sb.append(" " + i) sb.append sb " " + i " " i System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb System.exit(0) System.exit System 0 String[] args args public class Main{

    static StringBuilder sb;

    public static void main(String[] args) {
	try {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    List<String> lines = new ArrayList<String>();

	    for (String line = br.readLine(); line != null; line = br.readLine()) {
		lines.add(line);
	    }
	    //lines.add("60");
	    br.close();

	    Integer n = Integer.parseInt(lines.get(0));
	    sb = new StringBuilder();

	    for (int i = 1; i <= n; i++) {
		if (i%3==0) {
		    sb.append(" " + i);
		} else if (i%10==3) {
		    sb.append(" " + i);
		} else if (String.valueOf(i).contains("3")) {
		    sb.append(" " + i);
		}
	    }
	    System.out.println(sb.toString());
	    System.exit(0);

	} catch (Exception e) {
	    System.out.println(e.getMessage());
	    System.out.println(Arrays.toString(e.getStackTrace()));
	    System.exit(0);
	}
    }
} public class Main{

    static StringBuilder sb;

    public static void main(String[] args) {
	try {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    List<String> lines = new ArrayList<String>();

	    for (String line = br.readLine(); line != null; line = br.readLine()) {
		lines.add(line);
	    }
	    //lines.add("60");
	    br.close();

	    Integer n = Integer.parseInt(lines.get(0));
	    sb = new StringBuilder();

	    for (int i = 1; i <= n; i++) {
		if (i%3==0) {
		    sb.append(" " + i);
		} else if (i%10==3) {
		    sb.append(" " + i);
		} else if (String.valueOf(i).contains("3")) {
		    sb.append(" " + i);
		}
	    }
	    System.out.println(sb.toString());
	    System.exit(0);

	} catch (Exception e) {
	    System.out.println(e.getMessage());
	    System.out.println(Arrays.toString(e.getStackTrace()));
	    System.exit(0);
	}
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

// void call(int n){
//   int i = 1;
//  CHECK_NUM:
//   int x = i;
//   if ( x % 3 == 0 ){
//     cout << " " << i;
//     goto END_CHECK_NUM;
//   }
//  INCLUDE3:
//   if ( x % 10 == 3 ){
//     cout << " " << i;
//     goto END_CHECK_NUM;
//   }
//   x /= 10;
//   if ( x ) goto INCLUDE3;
//  END_CHECK_NUM:
//   if ( ++i <= n ) goto CHECK_NUM;
//
//   cout << endl;
// }

public class Main{

    static StringBuilder sb;

    public static void main(String[] args) {
	try {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    List<String> lines = new ArrayList<String>();

	    for (String line = br.readLine(); line != null; line = br.readLine()) {
		lines.add(line);
	    }
	    //lines.add("60");
	    br.close();

	    Integer n = Integer.parseInt(lines.get(0));
	    sb = new StringBuilder();

	    for (int i = 1; i <= n; i++) {
		if (i%3==0) {
		    sb.append(" " + i);
		} else if (i%10==3) {
		    sb.append(" " + i);
		} else if (String.valueOf(i).contains("3")) {
		    sb.append(" " + i);
		}
	    }
	    System.out.println(sb.toString());
	    System.exit(0);

	} catch (Exception e) {
	    System.out.println(e.getMessage());
	    System.out.println(Arrays.toString(e.getStackTrace()));
	    System.exit(0);
	}
    }
}