from __future__ import annotations

import random
from collections.abc import Iterable
from typing import Any, Generic, TypeVar

UpperCAmelCase				 =   TypeVar("""T""", bound=bool)






class 				_SCREAMING_SNAKE_CASE( Generic[T]						):
   def __init__(     self				,  lowerCAmelCase_     )						->None:
        a	:     T						      =    value
        a	:     RandomizedHeapNode[T] | None						      =    None
        a	:     RandomizedHeapNode[T] | None						      =    None
   @property
   def _lowercase(     self     )						->T:
        return self._value


   @staticmethod
   def _lowercase(     lowerCAmelCase_				,  lowerCAmelCase_     )						->RandomizedHeapNode[T] | None:
        if not roota:
             return roota

        if not roota:
             return roota

        if roota.value > roota.value:
             a      ,				a	:     Dict						      =    roota, roota

        if random.choice([True, False]     ):
             a      ,				a	:     Dict						      =    roota.right, roota.left

        a	:     Optional[int]						      =    RandomizedHeapNode.merge(roota.left				,  lowerCAmelCase_     )

        return roota






class 				_SCREAMING_SNAKE_CASE( Generic[T]						):
   def __init__(     self				,  lowerCAmelCase_ = ()     )						->None:
        a	:     RandomizedHeapNode[T] | None						      =    None

        if data:
             for item in data:
                  self.insert(lowerCAmelCase_     )
   def _lowercase(     self				,  lowerCAmelCase_     )						->None:
        a	:     List[str]						      =    RandomizedHeapNode.merge(self._root				,  RandomizedHeapNode(lowerCAmelCase_     )     )
   def _lowercase(     self     )						->T | None:
        a	:     Any						      =    self.top()

        if self._root is None:
             return None

        a	:     Optional[Any]						      =    RandomizedHeapNode.merge(self._root.left				,  self._root.right     )

        return result
   def _lowercase(     self     )						->T:
        if not self._root:
             raise IndexError('''Can\'t get top element for the empty heap.'''     )
        return self._root.value
   def _lowercase(     self     )						->None:
        a	:     Optional[int]						      =    None
   def _lowercase(     self     )						->list[Any]:
        a	:     Optional[int]						      =    []
        while self:
             result.append(self.pop()     )

        return result


   def __bool__(     self     )						->bool:
        return self._root is not None


if __name__ == "__main__":
  import doctest

  doctest.testmod()
import math







def 						UpperCAmelCase							(		lowerCAmelCase_							)						->						int:
     return sum(int(lowerCAmelCase_							) for digit in str(lowerCAmelCase_							)							)







def 						UpperCAmelCase							(		lowerCAmelCase_ = 3_0							)						->						int:
     a	:     Optional[int]						      =    []
     for digit in range(2    ,   1_0_0							):
          for power in range(2    ,   1_0_0							):
               a	:     List[str]						      =    int(math.pow(lowerCAmelCase_    ,   lowerCAmelCase_							)							)
               if digit == digit_sum(lowerCAmelCase_							):
                    digit_to_powers.append(lowerCAmelCase_							)

     digit_to_powers.sort()
     return digit_to_powers[n - 1]


if __name__ == "__main__":
  print(solution())