

Input

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

Output

Output a single integer.

Example

Input

3


Output

27
def sumDigits(n):
    answer = 0
    while n > 0:
        answer += n%10
        n = n // 10
    return answer

def listFactors(n):
    # Precondition:  n <= 30
    answer = []
    while n > 1:
        for i in range(2,n+1):
            if n%i == 0:
                answer.append(i)
                n = n // i
                break
    return answer

# print("Input i")                  
i = int(input())

test = 4
numsofar = 0
while numsofar < i:
    # print("Checking " + str(test))
    if len(listFactors(test)) > 1:  # It's composite
        # print("Test is composite")
        numsum = sumDigits(test)
        factorsum = 0
        for factor in listFactors(test):
            factorsum += sumDigits(factor)
        if numsum == factorsum:    # We've found one
            numsofar += 1
            if numsofar == i:
                print(test)
                break
    test += 1
        


