program sample
  implicit none
  integer(8) :: i,j,x,y,count
  integer(8) :: a(41)
    
  read(*,*) x

  a(1) =1
  
  
  do i=2,9
     a(i) = 2**i
  end do
    
  do i=10,14
     a(i) = 3**(i-8)
  end do

  do i=15,17
     a(i) = 5**(i-13)
  end do
  do i=18,19
     a(i) =6**(i-16)
  end do

  do i=20,21
     a(i) = 7**(i-18)
  end do

  do i=22,23
     a(i) = 10**(i-20)
  end do

  do i=24,28
     a(i) = (i-13)**2
  end do

  do i=29,36
     a(i) = (i-12)**2
  end do

  a(37) = 26**2
  
  do i=38,41
     a(i)=(i-10)**2
  end do

  do i=1,41
     do j=i,41
        if (a(i)>a(j)) then
           y=a(i)
           a(i)=a(j)
           a(j)=y
        end if
     end do
  end do

  do i=1,41
     if (a(i) <= x) then
        count=a(i)
     end if
  end do

  write(*,*) count
  
  stop
end program sample