PROGRAM ATCODER

implicit none
integer :: n, i, gcd, x, y, t
integer,allocatable :: a(:)

read(*,*) n
allocate(a(n))
read(*,*) (a(i), i = 1,n)

call hs(n,a)

gcd = a(1)
do i = 1, n-1
x = a(i+1)
y = gcd
	do 
    	if(mod(x,y) == 0) then
        	gcd = y
            exit
		end if
        t = y
        y = mod(x,y)
        x = t
    end do
    
    if(gcd == 1)then
    	write(*,'(i0)') gcd
        stop
    end if
end do

write(*,'(i0)') gcd
 
END PROGRAM ATCODER

subroutine hs(n,array)
  implicit none
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
  
  integer ::i,k,j,l
  integer :: t
  
  if(n <= 0)then
     write(6,*)"Error, at heapsort"; stop
  endif
  if(n == 1)return
 
  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j <= k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
 
  return
end subroutine hs