import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class message_vd {
	BufferedReader in;
	StringTokenizer str;
	PrintWriter out;
	String SK;

	String next() throws IOException {
		while ((str == null) || (!str.hasMoreTokens())) {
			SK = in.readLine();
			if (SK == null)
				return null;
			str = new StringTokenizer(SK);
		}
		return str.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	void solve() throws IOException {
		int m = (int) 1e+7;
		int[] prime = new int[m + 1];
		prime[0] = prime[1] = 1;
		for (int i = 2; i * i <= m; i++) {
			if (prime[i] == 0) {
				for (int j = i * i; j <= m; j += i) {
					prime[j] = 1;
				}
			}
		}
		int k = 0;
		for (int i = 2; 2*i+1 <= m; i++) {
			if (prime[i] + prime[2 * i + 1] == 0) {
				k++;
			}
		}
		int n = nextInt();
		assert n >= 1;
		assert n <= 30000;
		for (int i = 1; i <= m; i++) {
			if (prime[i] + prime[2 * i + 1] == 0) {
				n--;
				if (n == 0) {
					out.println(i);
					return;
				}
			}
		}
	}

	void run() throws IOException {
		in = new BufferedReader(new FileReader("message.in"));
		out = new PrintWriter("message.out");
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new message_vd().run();
	}

}