program brick_break
  implicit none
  integer :: n, a(200000) = 0, i, k = 0
  read(*,*) n
  read(*,*) a(1:n)
  do i = 1, n
    if (a(i) == k+1) then
      k = k+1
    end if
  end do
  if (k == 0) k = n+1
  write(*,'(i0)') n-k
end program brick_break
; ModuleID = 'FIRModule'
source_filename = "FIRModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@_QFEa = internal global [200000 x i32] zeroinitializer
@_QFEk = internal unnamed_addr global i32 0
@_QQcl.8a105799f452539fd4d2870001d9203e = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_2819/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.8a105799f452539fd4d2870001d9203e, i32 4)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.8a105799f452539fd4d2870001d9203e, i32 5)
  %7 = load i32, ptr %2, align 4, !tbaa !3
  %8 = call i32 @llvm.smax.i32(i32 %7, i32 0)
  %9 = zext i32 %8 to i64
  store ptr @_QFEa, ptr %1, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 4, ptr %.fca.1.gep, align 8, !tbaa !7
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 9, ptr %.fca.4.gep, align 1, !tbaa !7
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  store i64 %9, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 2
  store i64 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %10 = call i1 @_FortranAioInputDescriptor(ptr %6, ptr nonnull %1)
  %11 = call i32 @_FortranAioEndIoStatement(ptr %6)
  %12 = load i32, ptr %2, align 4, !tbaa !3
  %_QFEk.promoted = load i32, ptr @_QFEk, align 4, !tbaa !3
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %14 = zext i32 %12 to i64
  %xtraiter = and i64 %14, 1
  %15 = icmp eq i32 %12, 1
  br i1 %15, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %14, 4294967294
  br label %.lr.ph

.lr.ph:                                           ; preds = %29, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %29 ]
  %16 = phi i32 [ %_QFEk.promoted, %.lr.ph.preheader.new ], [ %30, %29 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %29 ]
  %17 = add nsw i64 %indvars.iv, -1
  %18 = getelementptr [200000 x i32], ptr @_QFEa, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !3
  %20 = add i32 %16, 1
  %21 = icmp eq i32 %19, %20
  br i1 %21, label %22, label %.lr.ph.1

22:                                               ; preds = %.lr.ph
  store i32 %19, ptr @_QFEk, align 4, !tbaa !3
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %22, %.lr.ph
  %23 = phi i32 [ %19, %22 ], [ %16, %.lr.ph ]
  %24 = getelementptr [200000 x i32], ptr @_QFEa, i64 0, i64 %indvars.iv
  %25 = load i32, ptr %24, align 4, !tbaa !3
  %26 = add i32 %23, 1
  %27 = icmp eq i32 %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %.lr.ph.1
  store i32 %25, ptr @_QFEk, align 4, !tbaa !3
  br label %29

29:                                               ; preds = %28, %.lr.ph.1
  %30 = phi i32 [ %25, %28 ], [ %23, %.lr.ph.1 ]
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa.loopexit, label %.lr.ph

._crit_edge.loopexit.unr-lcssa.loopexit:          ; preds = %29
  %31 = add nuw nsw i64 %indvars.iv, 1
  br label %._crit_edge.loopexit.unr-lcssa

._crit_edge.loopexit.unr-lcssa:                   ; preds = %._crit_edge.loopexit.unr-lcssa.loopexit, %.lr.ph.preheader
  %.lcssa.ph = phi i32 [ undef, %.lr.ph.preheader ], [ %30, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %31, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.unr = phi i32 [ %_QFEk.promoted, %.lr.ph.preheader ], [ %30, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %32 = getelementptr [200000 x i32], ptr @_QFEa, i64 0, i64 %indvars.iv.unr
  %33 = load i32, ptr %32, align 4, !tbaa !3
  %34 = add i32 %.unr, 1
  %35 = icmp eq i32 %33, %34
  br i1 %35, label %36, label %._crit_edge

36:                                               ; preds = %.lr.ph.epil
  store i32 %33, ptr @_QFEk, align 4, !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %36, %.lr.ph.epil, %0
  %37 = phi i32 [ %_QFEk.promoted, %0 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %33, %36 ], [ %.unr, %.lr.ph.epil ]
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %41

39:                                               ; preds = %._crit_edge
  %40 = add i32 %12, 1
  store i32 %40, ptr @_QFEk, align 4, !tbaa !3
  br label %41

41:                                               ; preds = %39, %._crit_edge
  %42 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.8a105799f452539fd4d2870001d9203e, i32 12)
  %43 = load i32, ptr %2, align 4, !tbaa !3
  %44 = load i32, ptr @_QFEk, align 4, !tbaa !3
  %45 = sub i32 %43, %44
  %46 = call i1 @_FortranAioOutputInteger32(ptr %42, i32 %45)
  %47 = call i32 @_FortranAioEndIoStatement(ptr %42)
  ret void
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare i1 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #0

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
