program main
  implicit none
  integer :: N
  integer,allocatable :: A(:)
  integer :: Amin, i_loop,Amin_bf
  integer :: i,j,k
  read(*,*) N
  allocate( A(N) )
  read(*,*) A
  Amin = minval(A)
  where ( mod(A,Amin) == 0 )   A = Amin
  ! calc mod
  do 
     where(A > Amin ) A = A-Amin
     where ( mod(A,Amin) == 0 )   A = Amin
     if ( any(A < Amin ) ) then
        Amin = minval(A,A>0)
     end if
     if ( all( A == Amin ) ) exit
  end do
  write(*,'(i0)') minval(A,A >0 )
  deallocate(A)
  stop
contains
  recursive function iqsort(ix) result(ires)
        integer, allocatable :: ires(:)
        integer, intent(in)  :: ix(:)
        integer :: k
        if (size(ix) <= 1) then 
          ires = ix
        else  
          k = ix(size(ix) / 2)
          ires = [iqsort(pack(ix, ix < k)), pack(ix, ix == k), iqsort(pack(ix, ix > k))] 
        end if
      end function iqsort  
end program main
