program decrease
  implicit none
  integer :: n, i
  integer(8) :: a(50), m, t
  a = 0_8
  read(*,*) n
  read(*,*) a(1:n)
  t = 0_8
  do
    m = maxval(a(1:n))
    if (m.lt.int(n,8)) exit
    do i = 1, n
      if (a(i).eq.m) then
        a(i) = a(i) - int(n+1,8)
        exit
      end if
    end do
    a(1:n) = a(1:n) + 1_8
    t = t + 1_8
  end do
  write(*,'(i0)') t
  stop
end program decrease