program main
  implicit none
  integer :: n, i, j, m, res
  integer, allocatable :: s(:)
  character(4) :: si
  character(1), allocatable :: c(:)
  read (*, *) n, m
  allocate (s(m), c(m))
  do i = 1, m
    read (*, *) s(i), c(i)
  end do

  res = -1
  iloop: do i = 0, 999
    write (si, "(i0)") i
    if (len(trim(si)) /= n) cycle iloop
    do j = 1, m
      if (si(s(j):s(j)) /= c(j)) cycle iloop
    end do
    res = i
    exit iloop
  end do iloop
  write (*, "(i0)") res
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"

@_QFEc.0 = internal unnamed_addr global ptr null
@_QFEs.0 = internal unnamed_addr global ptr null
@_QQcl.d3d05ec492b0563f6d1f873f778d9762 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_2275/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8 }, align 8
  %2 = alloca { ptr, i64, i32, i8, i8, i8, i8 }, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca [4 x i8], align 1
  %6 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.d3d05ec492b0563f6d1f873f778d9762, i32 7)
  %7 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %4, i32 4)
  %8 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %3, i32 4)
  %9 = call i32 @_FortranAioEndIoStatement(ptr %6)
  %10 = load i32, ptr %3, align 4, !tbaa !3
  %11 = call i32 @llvm.smax.i32(i32 %10, i32 0)
  %12 = zext i32 %11 to i64
  %13 = shl nuw nsw i64 %12, 2
  %14 = call ptr @malloc(i64 %13)
  store ptr %14, ptr @_QFEs.0, align 8, !tbaa !7
  %15 = call ptr @malloc(i64 %12)
  store ptr %15, ptr @_QFEc.0, align 8, !tbaa !7
  %16 = icmp sgt i32 %10, 0
  br i1 %16, label %.lr.ph.preheader, label %.preheader

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

.preheader:                                       ; preds = %.lr.ph, %0
  %.fca.1.gep115 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 1
  %.fca.2.gep117 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 2
  %.fca.3.gep119 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 3
  %.fca.4.gep121 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 4
  %.fca.5.gep123 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 5
  %.fca.6.gep125 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 6
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 1
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 2
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 3
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 4
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 5
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 6
  br label %26

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

26:                                               ; preds = %.preheader, %.loopexit343
  %.0274352 = phi i32 [ 0, %.preheader ], [ %48, %.loopexit343 ]
  %27 = call ptr @_FortranAioBeginInternalFormattedOutput(ptr nonnull %5, i64 4, ptr nonnull @_QQcl.28693029, i64 4, ptr null, ptr null, i64 0, ptr nonnull @_QQcl.d3d05ec492b0563f6d1f873f778d9762, i32 15)
  %28 = call i1 @_FortranAioOutputInteger32(ptr %27, i32 %.0274352)
  %29 = call i32 @_FortranAioEndIoStatement(ptr %27)
  store ptr %5, ptr %1, align 8, !tbaa !7
  store i64 4, ptr %.fca.1.gep115, align 8, !tbaa !7
  store i32 20180515, ptr %.fca.2.gep117, align 8, !tbaa !7
  store i8 0, ptr %.fca.3.gep119, align 4, !tbaa !7
  store i8 40, ptr %.fca.4.gep121, align 1, !tbaa !7
  store i8 0, ptr %.fca.5.gep123, align 2, !tbaa !7
  store i8 0, ptr %.fca.6.gep125, align 1, !tbaa !7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  store i8 0, ptr %.fca.3.gep, align 4, !tbaa !7
  store i8 40, ptr %.fca.4.gep, align 1, !tbaa !7
  store i8 2, ptr %.fca.5.gep, align 2, !tbaa !7
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %30 = call {} @_FortranATrim(ptr nonnull %2, ptr nonnull %1, ptr nonnull @_QQcl.d3d05ec492b0563f6d1f873f778d9762, i32 15)
  %.fca.0.load = load ptr, ptr %2, align 8, !tbaa !7
  %.fca.1.load = load i64, ptr %.fca.1.gep, align 8, !tbaa !7
  %31 = trunc i64 %.fca.1.load to i32
  %32 = load i32, ptr %4, align 4, !tbaa !3
  call void @free(ptr %.fca.0.load)
  %33 = icmp eq i32 %32, %31
  br i1 %33, label %34, label %.loopexit343

34:                                               ; preds = %26
  %35 = load i32, ptr %3, align 4, !tbaa !3
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %.lr.ph348.preheader, label %.loopexit

.lr.ph348.preheader:                              ; preds = %34
  %37 = add nuw i32 %35, 1
  %wide.trip.count = zext i32 %37 to i64
  br label %.lr.ph348

.lr.ph348:                                        ; preds = %.lr.ph348.preheader, %47
  %indvars.iv356 = phi i64 [ 1, %.lr.ph348.preheader ], [ %indvars.iv.next357, %47 ]
  %.unpack = load ptr, ptr @_QFEs.0, align 8, !tbaa !7
  %38 = add nsw i64 %indvars.iv356, -1
  %39 = getelementptr i32, ptr %.unpack, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !3
  %41 = sext i32 %40 to i64
  %42 = add nsw i64 %41, -1
  %43 = getelementptr [4 x [1 x i8]], ptr %5, i64 0, i64 %42
  %.unpack307 = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  %44 = add nsw i64 %indvars.iv356, -1
  %45 = getelementptr [1 x i8], ptr %.unpack307, i64 %44
  %46 = call i32 @_FortranACharacterCompareScalar1(ptr %43, ptr %45, i64 1, i64 1)
  %.not = icmp eq i32 %46, 0
  br i1 %.not, label %47, label %.loopexit343

47:                                               ; preds = %.lr.ph348
  %indvars.iv.next357 = add nuw nsw i64 %indvars.iv356, 1
  %exitcond359.not = icmp eq i64 %indvars.iv.next357, %wide.trip.count
  br i1 %exitcond359.not, label %.loopexit, label %.lr.ph348

.loopexit343:                                     ; preds = %.lr.ph348, %26
  %48 = add nuw nsw i32 %.0274352, 1
  %exitcond360.not = icmp eq i32 %48, 1000
  br i1 %exitcond360.not, label %.loopexit, label %26

.loopexit:                                        ; preds = %.loopexit343, %34, %47
  %.0 = phi i32 [ %.0274352, %47 ], [ %.0274352, %34 ], [ -1, %.loopexit343 ]
  %49 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.d3d05ec492b0563f6d1f873f778d9762, i32 23)
  %50 = call i1 @_FortranAioOutputInteger32(ptr %49, i32 %.0)
  %51 = call i32 @_FortranAioEndIoStatement(ptr %49)
  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 @_FortranAioInputAscii(ptr, ptr, i64) local_unnamed_addr

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

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

declare {} @_FortranATrim(ptr, ptr, ptr, i32) local_unnamed_addr

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

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

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

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

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