      PROGRAM brickBreak
      IMPLICIT NONE
      integer(16) :: n
      integer(16),allocatable :: a(:)
      integer(16) :: i,j,skip
      
      read*,n
      allocate( a(n) )
      read*,a
      
      
      
      j = 1
      skip = 0
      do i = 1,n
        if( a(i)==j )then
          j = j + 1
        else
          skip = skip + 1
        end if
      end do
      
      if( j==1 .and. skip==n )then
        print*,'-1'
      else
        print*,skip
      end if
      
      
      
      END PROGRAM
; 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.0 = internal unnamed_addr global ptr null
@_QFEa.8 = internal unnamed_addr global i64 0
@_QQcl.071e109cc9374bee21bb413c396faf04 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_2827/source.f\00"
@_QQcl.2D31 = linkonce constant [2 x i8] c"-1"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i128, align 8
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.071e109cc9374bee21bb413c396faf04, i32 7)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 16)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = load i128, ptr %2, align 8, !tbaa !3
  %7 = trunc i128 %6 to i64
  %8 = call i64 @llvm.smax.i64(i64 %7, i64 0)
  %9 = shl i64 %8, 4
  %10 = call ptr @malloc(i64 %9)
  store ptr %10, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %8, ptr @_QFEa.8, align 8, !tbaa !7
  %11 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.071e109cc9374bee21bb413c396faf04, i32 9)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack93.unpack.unpack95 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  store ptr %.unpack, 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 16, 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 11, 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 %.unpack93.unpack.unpack95, 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 16, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %12 = call i1 @_FortranAioInputDescriptor(ptr %11, ptr nonnull %1)
  %13 = call i32 @_FortranAioEndIoStatement(ptr %11)
  %14 = load i128, ptr %2, align 8, !tbaa !3
  %15 = trunc i128 %14 to i64
  %16 = icmp sgt i64 %15, 0
  br i1 %16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0
  %.unpack98 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %xtraiter = and i64 %15, 1
  %17 = icmp eq i64 %15, 1
  br i1 %17, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %15, -2
  br label %18

18:                                               ; preds = %18, %.lr.ph.new
  %19 = phi i64 [ 1, %.lr.ph.new ], [ %31, %18 ]
  %.0111 = phi i128 [ 0, %.lr.ph.new ], [ %.1.1, %18 ]
  %.075110 = phi i128 [ 1, %.lr.ph.new ], [ %.176.1, %18 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %18 ]
  %20 = add nsw i64 %19, -1
  %21 = getelementptr i128, ptr %.unpack98, i64 %20
  %22 = load i128, ptr %21, align 8, !tbaa !3
  %23 = icmp eq i128 %22, %.075110
  %24 = zext i1 %23 to i128
  %.176 = add i128 %.075110, %24
  %not. = xor i1 %23, true
  %25 = zext i1 %not. to i128
  %.1 = add i128 %.0111, %25
  %26 = getelementptr i128, ptr %.unpack98, i64 %19
  %27 = load i128, ptr %26, align 8, !tbaa !3
  %28 = icmp eq i128 %27, %.176
  %29 = zext i1 %28 to i128
  %.176.1 = add i128 %.176, %29
  %not..1 = xor i1 %28, true
  %30 = zext i1 %not..1 to i128
  %.1.1 = add i128 %.1, %30
  %31 = add nuw i64 %19, 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 %18

._crit_edge.loopexit.unr-lcssa.loopexit:          ; preds = %18
  %32 = add i64 %19, 1
  br label %._crit_edge.loopexit.unr-lcssa

._crit_edge.loopexit.unr-lcssa:                   ; preds = %._crit_edge.loopexit.unr-lcssa.loopexit, %.lr.ph
  %.176.lcssa.ph = phi i128 [ undef, %.lr.ph ], [ %.176.1, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.1.lcssa.ph = phi i128 [ undef, %.lr.ph ], [ %.1.1, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.unr = phi i64 [ 0, %.lr.ph ], [ %32, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.0111.unr = phi i128 [ 0, %.lr.ph ], [ %.1.1, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.075110.unr = phi i128 [ 1, %.lr.ph ], [ %.176.1, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %33 = getelementptr i128, ptr %.unpack98, i64 %.unr
  %34 = load i128, ptr %33, align 8, !tbaa !3
  %35 = icmp eq i128 %34, %.075110.unr
  %36 = zext i1 %35 to i128
  %.176.epil = add i128 %.075110.unr, %36
  %not..epil = xor i1 %35, true
  %37 = zext i1 %not..epil to i128
  %.1.epil = add i128 %.0111.unr, %37
  br label %._crit_edge.loopexit

._crit_edge.loopexit:                             ; preds = %._crit_edge.loopexit.unr-lcssa, %._crit_edge.loopexit.epilog-lcssa
  %.176.lcssa = phi i128 [ %.176.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.176.epil, %._crit_edge.loopexit.epilog-lcssa ]
  %.1.lcssa = phi i128 [ %.1.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.1.epil, %._crit_edge.loopexit.epilog-lcssa ]
  %38 = icmp eq i128 %.176.lcssa, 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %.075.lcssa = phi i1 [ true, %0 ], [ %38, %._crit_edge.loopexit ]
  %.0.lcssa = phi i128 [ 0, %0 ], [ %.1.lcssa, %._crit_edge.loopexit ]
  %39 = icmp eq i128 %.0.lcssa, %14
  %40 = and i1 %.075.lcssa, %39
  br i1 %40, label %41, label %44

41:                                               ; preds = %._crit_edge
  %42 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.071e109cc9374bee21bb413c396faf04, i32 24)
  %43 = call i1 @_FortranAioOutputAscii(ptr %42, ptr nonnull @_QQcl.2D31, i64 2)
  br label %47

44:                                               ; preds = %._crit_edge
  %45 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.071e109cc9374bee21bb413c396faf04, i32 26)
  %46 = call i1 @_FortranAioOutputInteger128(ptr %45, i128 %.0.lcssa)
  br label %47

47:                                               ; preds = %41, %44
  %.sink = phi ptr [ %42, %41 ], [ %45, %44 ]
  %48 = call i32 @_FortranAioEndIoStatement(ptr %.sink)
  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 @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputAscii(ptr, ptr, i64) local_unnamed_addr

declare i1 @_FortranAioOutputInteger128(ptr, i128) local_unnamed_addr

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { 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}
