

Input

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

Output

Output a single integer.

Example

Input

3


Output

27
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }
    static class Solver {
        public void solve(InputReader in, PrintWriter out) {
            int n = in.nextInt();
            List<Integer> l = new ArrayList<>();
            for (int i = 4; i <= (int)1e4; ++i) {
                if (sum(i) == dig(i) && !isPrime(i)) {
                    l.add(i);
                }
            }
            out.println(l.get(n - 1));
        }
        static int sum(int n) {
            int sum = 0;
            for (int i = 2; i * i <= n; ++i) {
                while (n % i == 0) {
                    sum += dig(i);
                    n /= i;
                }
            }
            if (n > 1) {
                sum += dig(n);
            }
            return sum;
        }
        static int dig(int n) {
            String s = "" + n;
            int sum = 0;
            for (int i = 0; i < s.length(); ++i) {
                sum += s.charAt(i) - '0';
            }
            return sum;
        }
        static boolean isPrime(int n) {
            if ((n % 2 == 0 || n % 3 == 0 || n % 5 == 0) && (n != 2 && n != 3 && n != 5)) {
                return false;
            }
            for (int i = 2; i * i <= n; i++) {
                if (n % i == 0) {
                    return false;
                }
            }
            return true;
        }

    } // wubba lubba dub dub
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreElements()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}