Program ABC118C

integer n,b,k
integer,allocatable::a(:)

read(*,*) n
allocate(a(n))
read(*,*) a

do i=1,n
 do j=i+1,n
  if (a(i)>a(j)) then
   b=a(i)
   a(i)=a(j)
   a(j)=b
  end if
 end do
end do

do while (a(n-1)/=0)

k=1
do j=1,n
if (a(k)/=0) then
do i=k+1,n
 a(i)=mod(a(i),a(1))
end do
go to 10
else
k=k+1
end if
end do

10 do i=1,n
 do j=i+1,n
  if (a(i)>a(j)) then
   b=a(i)
   a(i)=a(j)
   a(j)=b
  end if
 end do
end do

end do

write(*,*) a(n)

stop
end