#include <fstream>
#include <math.h>
#include <sstream>

using namespace std;

bool IsPrime(long long &a)
{
	if (a == 2 || a == 3)
	{
		return true;
	}
	if (a % 6 != 5 && a % 6 != 1)
	{
		return false;
	}
	else
	{
		for (long long i = 2; i <= sqrt(a); i++)
		{
			if (a % i == 0)
			{
				return false;
			}
		}
	}
	return true;
}

bool IsPrimeOP(long long a)
{
	if (a % 6 != 5 && a % 6 != 1)
	{
		return false;
	}
	else
	{
		for (long long i = 2; i < sqrt(a); i++)
		{
			if (a % i == 0)
			{
				return false;
			}
		}
	}
	return true;
}

long long merge(long long &a, long long &b)
{
	long long res;
	stringstream ss;
	ss << a << b;
	ss >> res;
	return res;
}

int main()
{
	ifstream input("Ngtoghep.inp");
	ofstream output("Ngtohep.out");

	int k;
	long long temp;
	long long a = 1;
	long long res;
	int i = 0;
	input >> k;
	while (k > 0)
	{
		do
		{
			a++;
		} while (!IsPrime(a));
		if (i % 2 == 0)
		{
			temp = a;
		}
		else if (IsPrimeOP(merge(temp, a)))
		{
			res = merge(temp, a);
			k--;
		}
		i++;
	}
	output << res;
	input.close();
	output.close();
	return 0;
}