module UIntegerSort
  implicit none
 
  private
 
  public QuickSortInteger
 
contains
    
  !!
  ! ピボット値の取得
  !
  subroutine GetPivotIntegerValue(array, n, a, b, pivot_value)
    integer(16), intent(inout) :: array(:), pivot_value
    integer(16), intent(in) :: n, a, b
 
    pivot_value = array((a + b) / 2)
  end subroutine
 
  !!
  ! ピボット値に従って値を分離
  !
  subroutine GetPartitionInteger(array, n, a, b, pivot)
    integer(16), intent(inout) :: array(:)
    integer(16), intent(in)  :: n, a, b
    integer(16), intent(out) :: pivot
 
    integer(16) :: buffer, pivot_value
    integer(16) :: l, r
 
    if (a == b) then
      pivot = 0
      return
    end if
 
    call GetPivotIntegerValue(array, n, a, b, pivot_value)
 
    l = a
    r = b
 
    do while(.true.)
      do while(array(l) < pivot_value)
        if (l >= b) exit
        l = l + 1
      end do
 
      do while(pivot_value < array(r))
        if (r <= a) exit
        r = r - 1
      end do
 
      if(r <= l) exit
 
      buffer   = array(l)
      array(l) = array(r)
      array(r) = buffer
 
      l = l + 1
      r = r - 1
    end do
 
    pivot = r
  end subroutine
 
  !!
  ! 配列の一部分をソートする。
  !
  recursive subroutine QuickSortIntegerSubarray(array, n, a, b)
    integer(16), intent(inout) :: array(:)
    integer(16), intent(in)    :: n, a, b
 
    integer(16) :: pivot
 
    call GetPartitionInteger(array, n, a, b, pivot)
    if (pivot /= 0) then
      call QuickSortIntegerSubarray(array, n, a, pivot)
      call QuickSortIntegerSubarray(array, n, pivot + 1, b)
    end if
  end subroutine
 
  !!
  ! 配列全体をソートする
  !
  subroutine QuickSortInteger(array, n)
    integer(16) :: array(:)
    integer(16) :: n
 
    call QuickSortIntegerSubarray(array, n, 1_16, n)
  end subroutine
end module
 
program test 
use UIntegerSort
implicit none
integer(16),allocatable::a(:)
integer(16)::n,i,ans
read*,n
allocate(a(n))
read*,a
call QuickSortInteger(a, N)
ans=1
do i=1, n
	ans=ans*a(i)
    	if(ans==0)then
        	exit
        else if(ans > 10**18_16)then
        	ans = -1
            exit
        else 
         	ans = ans
        end if
end do
print*,ans 
end program test