program main
      implicit none
      integer :: n, k, cnt, i
      integer, allocatable :: a(:)

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

      k = 1
      cnt = 0
      do i = 1, n
        if ( a(i) == k ) then
          k = k + 1
        else
          cnt = cnt + 1
        end if
      end do

      if ( k == 1 ) then
        print *, '-1'
      else 
        print *, cnt
      end if

end program main


; 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.9d5270fac0f51db9d9ce5544c8f39fbd = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_2826/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 i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.9d5270fac0f51db9d9ce5544c8f39fbd, i32 6)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = load i32, ptr %2, align 4, !tbaa !3
  %7 = call i32 @llvm.smax.i32(i32 %6, i32 0)
  %8 = zext i32 %7 to i64
  %9 = shl nuw nsw i64 %8, 2
  %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.9d5270fac0f51db9d9ce5544c8f39fbd, i32 8)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack92.unpack.unpack94 = 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 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 %.unpack92.unpack.unpack94, 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
  %12 = call i1 @_FortranAioInputDescriptor(ptr %11, ptr nonnull %1)
  %13 = call i32 @_FortranAioEndIoStatement(ptr %11)
  %14 = load i32, ptr %2, align 4, !tbaa !3
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge.thread

.lr.ph:                                           ; preds = %0
  %16 = zext i32 %14 to i64
  %.unpack97 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %xtraiter = and i64 %16, 1
  %17 = icmp eq i32 %14, 1
  br i1 %17, label %._crit_edge.unr-lcssa, label %.lr.ph.new

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

18:                                               ; preds = %18, %.lr.ph.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.new ], [ %indvars.iv.next.1, %18 ]
  %.0110 = phi i32 [ 1, %.lr.ph.new ], [ %.1.1, %18 ]
  %.074109 = phi i32 [ 0, %.lr.ph.new ], [ %.175.1, %18 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %18 ]
  %19 = add nsw i64 %indvars.iv, -1
  %20 = getelementptr i32, ptr %.unpack97, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !3
  %22 = icmp ne i32 %21, %.0110
  %23 = zext i1 %22 to i32
  %.175 = add i32 %.074109, %23
  %not. = xor i1 %22, true
  %24 = zext i1 %not. to i32
  %.1 = add i32 %.0110, %24
  %25 = getelementptr i32, ptr %.unpack97, i64 %indvars.iv
  %26 = load i32, ptr %25, align 4, !tbaa !3
  %27 = icmp ne i32 %26, %.1
  %28 = zext i1 %27 to i32
  %.175.1 = add i32 %.175, %28
  %not..1 = xor i1 %27, true
  %29 = zext i1 %not..1 to i32
  %.1.1 = add i32 %.1, %29
  %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.unr-lcssa.loopexit, label %18

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

._crit_edge.unr-lcssa:                            ; preds = %._crit_edge.unr-lcssa.loopexit, %.lr.ph
  %.175.lcssa.ph = phi i32 [ undef, %.lr.ph ], [ %.175.1, %._crit_edge.unr-lcssa.loopexit ]
  %.1.lcssa.ph = phi i32 [ undef, %.lr.ph ], [ %.1.1, %._crit_edge.unr-lcssa.loopexit ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %30, %._crit_edge.unr-lcssa.loopexit ]
  %.0110.unr = phi i32 [ 1, %.lr.ph ], [ %.1.1, %._crit_edge.unr-lcssa.loopexit ]
  %.074109.unr = phi i32 [ 0, %.lr.ph ], [ %.175.1, %._crit_edge.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.epilog-lcssa

._crit_edge.epilog-lcssa:                         ; preds = %._crit_edge.unr-lcssa
  %31 = getelementptr i32, ptr %.unpack97, i64 %indvars.iv.unr
  %32 = load i32, ptr %31, align 4, !tbaa !3
  %33 = icmp ne i32 %32, %.0110.unr
  %34 = zext i1 %33 to i32
  %.175.epil = add i32 %.074109.unr, %34
  %not..epil = xor i1 %33, true
  %35 = zext i1 %not..epil to i32
  %.1.epil = add i32 %.0110.unr, %35
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %._crit_edge.epilog-lcssa
  %.175.lcssa = phi i32 [ %.175.lcssa.ph, %._crit_edge.unr-lcssa ], [ %.175.epil, %._crit_edge.epilog-lcssa ]
  %.1.lcssa = phi i32 [ %.1.lcssa.ph, %._crit_edge.unr-lcssa ], [ %.1.epil, %._crit_edge.epilog-lcssa ]
  %36 = icmp eq i32 %.1.lcssa, 1
  br i1 %36, label %._crit_edge.thread, label %39

._crit_edge.thread:                               ; preds = %0, %._crit_edge
  %37 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.9d5270fac0f51db9d9ce5544c8f39fbd, i32 21)
  %38 = call i1 @_FortranAioOutputAscii(ptr %37, ptr nonnull @_QQcl.2D31, i64 2)
  br label %42

39:                                               ; preds = %._crit_edge
  %40 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.9d5270fac0f51db9d9ce5544c8f39fbd, i32 23)
  %41 = call i1 @_FortranAioOutputInteger32(ptr %40, i32 %.175.lcssa)
  br label %42

42:                                               ; preds = %._crit_edge.thread, %39
  %.sink = phi ptr [ %37, %._crit_edge.thread ], [ %40, %39 ]
  %43 = 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 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #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}
