sub f{$_**$n*$_>$x?last:$x%$_||f(local$x=$x/$_)for$_..4e4*--$n;$%+=!$n++}print f$x=<>=~$"+$',$n=$`,$_=2