program monster
  implicit none
  integer(8) :: n,i,attack,attacker
  integer(8), allocatable :: a(:)
  logical, allocatable :: mask(:)

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

  do while (sum(a) /= maxval(a))
    mask = a>0
    attack = minval(a,mask)
    attacker = minloc(a,1,mask)
    do i =1,n 
      a(i) = mod(a(i),attack)
    end do 
    a(attacker) = attack
  end do 
  print '(i0)', maxval(a)
  stop
end program monster