program main
    implicit none
    integer n, m
    integer, allocatable, dimension(:) :: s, c
    integer i,j,k,l, flag
    integer, dimension(3) :: x
    read(*,*) n, m
    allocate(s(m))
    allocate(c(m))

    do i = 1, m
        read(*,*) s(i), c(i)
    end do

    x = 0
    flag = 0

    do i = 1,m
        if(x(s(i)) /= 0) then
            if(x(s(i)) /= c(i)) then
                flag = -1
                exit
            end if
        else
            x(s(i)) = c(i)
        end if

!--------------
        if(n == 3) then
            if(s(i) == 1) then
                if(c(i) == 0) then
                    flag = -1
                end if
            end if
        end if

!---------------
        if(n == 2) then
            if(s(i) == 1) then
                if(c(i) == 0) then
                    flag = -1
                end if
            end if
        end if

    end do

    
    if (flag == -1) then
        write(*,*) -1
    else
        if (n == 3) then
            if (x(1) == 0) then
                x(1) = 1
            end if
            write(*,*) 100*x(1)+10*x(2)+x(3)
        else if (n == 2) then
            if (x(1) == 0) then
                x(1) = 1
            end if
            write(*,*) 10*x(1)+x(2)
        else
            write(*,*) x(1)
        end if
        
    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"

@_QFEc.0 = internal unnamed_addr global ptr null
@_QFEs.0 = internal unnamed_addr global ptr null
@_QQcl.5f14cad8f71f8a898c9f1e61acbd4361 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_2286/source.f\00"
@_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 i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [3 x i32], align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.5f14cad8f71f8a898c9f1e61acbd4361, i32 7)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 4)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %1, i32 4)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %8 = load i32, ptr %1, align 4, !tbaa !3
  %9 = call i32 @llvm.smax.i32(i32 %8, i32 0)
  %10 = zext i32 %9 to i64
  %11 = shl nuw nsw i64 %10, 2
  %12 = call ptr @malloc(i64 %11)
  store ptr %12, ptr @_QFEs.0, align 8, !tbaa !7
  %13 = call ptr @malloc(i64 %11)
  store ptr %13, ptr @_QFEc.0, align 8, !tbaa !7
  %14 = icmp sgt i32 %8, 0
  br i1 %14, label %.lr.ph.preheader, label %.preheader.thread

.preheader.thread:                                ; preds = %0
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %3, i8 0, i64 12, i1 false), !tbaa !3
  br label %._crit_edge.thread

.lr.ph.preheader:                                 ; preds = %0
  %15 = zext i32 %8 to i64
  br label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %.pre = load i32, ptr %1, align 4, !tbaa !3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %3, i8 0, i64 12, i1 false), !tbaa !3
  %16 = icmp sgt i32 %.pre, 0
  br i1 %16, label %.lr.ph422, label %._crit_edge.thread

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %17 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.5f14cad8f71f8a898c9f1e61acbd4361, i32 12)
  %.unpack390 = load ptr, ptr @_QFEs.0, align 8, !tbaa !7
  %18 = add nsw i64 %indvars.iv, -1
  %19 = getelementptr i32, ptr %.unpack390, i64 %18
  %20 = call i1 @_FortranAioInputInteger(ptr %17, ptr %19, i32 4)
  %.unpack402 = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  %21 = add nsw i64 %indvars.iv, -1
  %22 = getelementptr i32, ptr %.unpack402, i64 %21
  %23 = call i1 @_FortranAioInputInteger(ptr %17, ptr %22, i32 4)
  %24 = call i32 @_FortranAioEndIoStatement(ptr %17)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %15
  br i1 %exitcond.not, label %.preheader, label %.lr.ph

.lr.ph422:                                        ; preds = %.preheader
  %.unpack = load ptr, ptr @_QFEs.0, align 8, !tbaa !7
  %.unpack377 = load ptr, ptr @_QFEc.0, align 8
  %25 = load i32, ptr %2, align 4
  %.fr = freeze i32 %25
  switch i32 %.fr, label %.lr.ph422.split.preheader [
    i32 3, label %.lr.ph422.split.us.preheader
    i32 2, label %.lr.ph422.split.us423.preheader
  ]

.lr.ph422.split.us423.preheader:                  ; preds = %.lr.ph422
  %26 = add nuw i32 %.pre, 1
  %wide.trip.count = zext i32 %26 to i64
  br label %.lr.ph422.split.us423

.lr.ph422.split.us.preheader:                     ; preds = %.lr.ph422
  %27 = add nuw i32 %.pre, 1
  %wide.trip.count445 = zext i32 %27 to i64
  br label %.lr.ph422.split.us

.lr.ph422.split.preheader:                        ; preds = %.lr.ph422
  %28 = add nuw i32 %.pre, 1
  %wide.trip.count450 = zext i32 %28 to i64
  br label %.lr.ph422.split

.lr.ph422.split.us:                               ; preds = %.lr.ph422.split.us.preheader, %.thread.us
  %indvars.iv442 = phi i64 [ 1, %.lr.ph422.split.us.preheader ], [ %indvars.iv.next443, %.thread.us ]
  %.0282420.us = phi i32 [ 0, %.lr.ph422.split.us.preheader ], [ %.2.us, %.thread.us ]
  %29 = add nsw i64 %indvars.iv442, -1
  %30 = getelementptr i32, ptr %.unpack, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !3
  %32 = sext i32 %31 to i64
  %33 = add nsw i64 %32, -1
  %34 = getelementptr [3 x i32], ptr %3, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !3
  %.not.us = icmp eq i32 %35, 0
  %36 = add nsw i64 %indvars.iv442, -1
  %37 = getelementptr i32, ptr %.unpack377, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !3
  br i1 %.not.us, label %40, label %39

39:                                               ; preds = %.lr.ph422.split.us
  %.not389.us = icmp eq i32 %35, %38
  br i1 %.not389.us, label %41, label %.thread416

40:                                               ; preds = %.lr.ph422.split.us
  store i32 %38, ptr %34, align 4, !tbaa !3
  br label %41

41:                                               ; preds = %40, %39
  %42 = icmp eq i32 %31, 1
  br i1 %42, label %43, label %.thread.us

43:                                               ; preds = %41
  %44 = add nsw i64 %indvars.iv442, -1
  %45 = getelementptr i32, ptr %.unpack377, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !3
  %47 = icmp eq i32 %46, 0
  %spec.select.us = select i1 %47, i32 -1, i32 %.0282420.us
  br label %.thread.us

.thread.us:                                       ; preds = %43, %41
  %.2.us = phi i32 [ %spec.select.us, %43 ], [ %.0282420.us, %41 ]
  %indvars.iv.next443 = add nuw nsw i64 %indvars.iv442, 1
  %exitcond446.not = icmp eq i64 %indvars.iv.next443, %wide.trip.count445
  br i1 %exitcond446.not, label %._crit_edge, label %.lr.ph422.split.us

.lr.ph422.split.us423:                            ; preds = %.lr.ph422.split.us423.preheader, %.thread.us429
  %indvars.iv438 = phi i64 [ 1, %.lr.ph422.split.us423.preheader ], [ %indvars.iv.next439, %.thread.us429 ]
  %.0282420.us425 = phi i32 [ 0, %.lr.ph422.split.us423.preheader ], [ %.2.us430, %.thread.us429 ]
  %48 = add nsw i64 %indvars.iv438, -1
  %49 = getelementptr i32, ptr %.unpack, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !3
  %51 = sext i32 %50 to i64
  %52 = add nsw i64 %51, -1
  %53 = getelementptr [3 x i32], ptr %3, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !3
  %.not.us427 = icmp eq i32 %54, 0
  %55 = add nsw i64 %indvars.iv438, -1
  %56 = getelementptr i32, ptr %.unpack377, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !3
  br i1 %.not.us427, label %59, label %58

58:                                               ; preds = %.lr.ph422.split.us423
  %.not389.us428 = icmp eq i32 %54, %57
  br i1 %.not389.us428, label %60, label %.thread416

59:                                               ; preds = %.lr.ph422.split.us423
  store i32 %57, ptr %53, align 4, !tbaa !3
  br label %60

60:                                               ; preds = %59, %58
  %61 = icmp eq i32 %50, 1
  br i1 %61, label %62, label %.thread.us429

62:                                               ; preds = %60
  %63 = add nsw i64 %indvars.iv438, -1
  %64 = getelementptr i32, ptr %.unpack377, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !3
  %66 = icmp eq i32 %65, 0
  %spec.select414.us = select i1 %66, i32 -1, i32 %.0282420.us425
  br label %.thread.us429

.thread.us429:                                    ; preds = %62, %60
  %.2.us430 = phi i32 [ %.0282420.us425, %60 ], [ %spec.select414.us, %62 ]
  %indvars.iv.next439 = add nuw nsw i64 %indvars.iv438, 1
  %exitcond441.not = icmp eq i64 %indvars.iv.next439, %wide.trip.count
  br i1 %exitcond441.not, label %._crit_edge, label %.lr.ph422.split.us423

.lr.ph422.split:                                  ; preds = %.lr.ph422.split.preheader, %.thread
  %indvars.iv447 = phi i64 [ 1, %.lr.ph422.split.preheader ], [ %indvars.iv.next448, %.thread ]
  %67 = add nsw i64 %indvars.iv447, -1
  %68 = getelementptr i32, ptr %.unpack, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !3
  %70 = sext i32 %69 to i64
  %71 = add nsw i64 %70, -1
  %72 = getelementptr [3 x i32], ptr %3, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !3
  %.not = icmp eq i32 %73, 0
  %74 = add nsw i64 %indvars.iv447, -1
  %75 = getelementptr i32, ptr %.unpack377, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !3
  br i1 %.not, label %78, label %77

77:                                               ; preds = %.lr.ph422.split
  %.not389 = icmp eq i32 %73, %76
  br i1 %.not389, label %.thread, label %.thread416

78:                                               ; preds = %.lr.ph422.split
  store i32 %76, ptr %72, align 4, !tbaa !3
  br label %.thread

.thread:                                          ; preds = %77, %78
  %indvars.iv.next448 = add nuw nsw i64 %indvars.iv447, 1
  %exitcond451.not = icmp eq i64 %indvars.iv.next448, %wide.trip.count450
  br i1 %exitcond451.not, label %._crit_edge.thread, label %.lr.ph422.split

._crit_edge:                                      ; preds = %.thread.us429, %.thread.us
  %.0282.lcssa = phi i32 [ %.2.us, %.thread.us ], [ %.2.us430, %.thread.us429 ]
  %79 = icmp eq i32 %.0282.lcssa, -1
  br i1 %79, label %.thread416, label %._crit_edge.thread

.thread416:                                       ; preds = %58, %39, %77, %._crit_edge
  %80 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.5f14cad8f71f8a898c9f1e61acbd4361, i32 50)
  %81 = call i1 @_FortranAioOutputInteger32(ptr %80, i32 -1)
  br label %109

._crit_edge.thread:                               ; preds = %.thread, %.preheader.thread, %.preheader, %._crit_edge
  %82 = load i32, ptr %2, align 4, !tbaa !3
  switch i32 %82, label %105 [
    i32 3, label %83
    i32 2, label %96
  ]

83:                                               ; preds = %._crit_edge.thread
  %84 = load i32, ptr %3, align 4, !tbaa !3
  %85 = icmp eq i32 %84, 0
  %86 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.5f14cad8f71f8a898c9f1e61acbd4361, i32 56)
  %.op456 = mul i32 %84, 100
  %87 = select i1 %85, i32 100, i32 %.op456
  %88 = getelementptr inbounds [3 x i32], ptr %3, i64 0, i64 1
  %89 = load i32, ptr %88, align 4, !tbaa !3
  %90 = mul i32 %89, 10
  %91 = add i32 %90, %87
  %92 = getelementptr inbounds [3 x i32], ptr %3, i64 0, i64 2
  %93 = load i32, ptr %92, align 4, !tbaa !3
  %94 = add i32 %91, %93
  %95 = call i1 @_FortranAioOutputInteger32(ptr %86, i32 %94)
  br label %109

96:                                               ; preds = %._crit_edge.thread
  %97 = load i32, ptr %3, align 4, !tbaa !3
  %98 = icmp eq i32 %97, 0
  %99 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.5f14cad8f71f8a898c9f1e61acbd4361, i32 61)
  %.op = mul i32 %97, 10
  %100 = select i1 %98, i32 10, i32 %.op
  %101 = getelementptr inbounds [3 x i32], ptr %3, i64 0, i64 1
  %102 = load i32, ptr %101, align 4, !tbaa !3
  %103 = add i32 %100, %102
  %104 = call i1 @_FortranAioOutputInteger32(ptr %99, i32 %103)
  br label %109

105:                                              ; preds = %._crit_edge.thread
  %106 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.5f14cad8f71f8a898c9f1e61acbd4361, i32 63)
  %107 = load i32, ptr %3, align 4, !tbaa !3
  %108 = call i1 @_FortranAioOutputInteger32(ptr %106, i32 %107)
  br label %109

109:                                              ; preds = %.thread416, %83, %96, %105
  %.sink = phi ptr [ %80, %.thread416 ], [ %86, %83 ], [ %99, %96 ], [ %106, %105 ]
  %110 = 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 ptr @_FortranAioBeginExternalListOutput(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) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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}
