

Input

The input contains a single integer a (1 ≤ a ≤ 30).

Output

Output a single integer.

Example

Input

3


Output

27
import java.math.BigInteger;
import java.util.*;

public class P784A
{
	public static void main(String[] args) throws Exception
	{
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int c = 0;
		int n = 0;
		while (c < a)
		{
			n++;
			if (!prime(n))
			{
				int s1 = sum(n);
				ArrayList<Integer> prime = factors(n);
				int s2 = 0;
				for (int i = 0; i < prime.size(); i++)
					s2 += sum(prime.get(i));
				if (s1 == s2)
					c++;
			}
		}
		System.out.println(n);
	}

	private static ArrayList<Integer> factors(int n)
	{
		ArrayList<Integer> prime = new ArrayList<>();
		while (n > 1)
		{
			if (prime(n))
			{
				prime.add(n);
				break;
			}
			for (int i = 2; i < n; i++)
			{
				if (n % i == 0)
				{
					prime.add(i);
					n /= i;
					break;
				}
			}
		}
		return prime;
	}

	private static boolean prime(int n)
	{
		return BigInteger.valueOf(n).isProbablePrime(100);
	}

	private static int sum(int n)
	{
		int s = 0;
		char[] c = (""+n).toCharArray();
		for (int i = 0; i < c.length; i++)
			s += c[i]-'0';
		return s;
	}
}
