program kadai
implicit none

integer  ::  n,m,i,j,flag
integer,allocatable  ::  L(:)
integer,allocatable  ::  R(:)

read(*,*) n,m

allocate(L(m))
allocate(R(m))

do i=1,m
    read(*,*) L(i),R(i)
end do

flag=minval(R)-maxval(L)+1

if (flag<0) then
    flag=0
end if
write(*,*) flag


end program kadai
; 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"

@_QFEl.0 = internal unnamed_addr global ptr null
@_QFEl.8 = internal unnamed_addr global i64 0
@_QFEr.0 = internal unnamed_addr global ptr null
@_QFEr.8 = internal unnamed_addr global i64 0
@_QQcl.db55e11ab4d60c05287437c9d2d61bc4 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_4229/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 { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.db55e11ab4d60c05287437c9d2d61bc4, i32 8)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 4)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %8 = load i32, ptr %2, 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 @_QFEl.0, align 8, !tbaa !7
  store i64 %10, ptr @_QFEl.8, align 8, !tbaa !7
  %13 = call ptr @malloc(i64 %11)
  store ptr %13, ptr @_QFEr.0, align 8, !tbaa !7
  store i64 %10, ptr @_QFEr.8, align 8, !tbaa !7
  %14 = icmp sgt i32 %8, 0
  br i1 %14, label %.lr.ph.preheader, label %._crit_edge

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

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %16 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.db55e11ab4d60c05287437c9d2d61bc4, i32 14)
  %.unpack233 = load ptr, ptr @_QFEl.0, align 8, !tbaa !7
  %17 = add nsw i64 %indvars.iv, -1
  %18 = getelementptr i32, ptr %.unpack233, i64 %17
  %19 = call i1 @_FortranAioInputInteger(ptr %16, ptr %18, i32 4)
  %.unpack245 = load ptr, ptr @_QFEr.0, align 8, !tbaa !7
  %20 = add nsw i64 %indvars.iv, -1
  %21 = getelementptr i32, ptr %.unpack245, i64 %20
  %22 = call i1 @_FortranAioInputInteger(ptr %16, ptr %21, i32 4)
  %23 = call i32 @_FortranAioEndIoStatement(ptr %16)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %15
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.unpack.pre = load ptr, ptr @_QFEr.0, align 8, !tbaa !7
  %.unpack216.unpack.unpack218.pre = load i64, ptr @_QFEr.8, align 8, !tbaa !7
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %.unpack216.unpack.unpack218 = phi i64 [ %.unpack216.unpack.unpack218.pre, %._crit_edge.loopexit ], [ %10, %0 ]
  %.unpack = phi ptr [ %.unpack.pre, %._crit_edge.loopexit ], [ %13, %0 ]
  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 %.unpack216.unpack.unpack218, 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
  %24 = call i32 @_FortranAMinvalInteger4(ptr nonnull %1, ptr nonnull @_QQcl.db55e11ab4d60c05287437c9d2d61bc4, i32 17, i32 0, ptr null)
  %.unpack221 = load ptr, ptr @_QFEl.0, align 8, !tbaa !7
  %.unpack228.unpack.unpack230 = load i64, ptr @_QFEl.8, align 8, !tbaa !7
  %25 = icmp sgt i64 %.unpack228.unpack.unpack230, 0
  br i1 %25, label %.lr.ph.i.preheader, label %_FortranAMaxvalInteger4x1_contract_simplified.exit

.lr.ph.i.preheader:                               ; preds = %._crit_edge
  %min.iters.check = icmp ult i64 %.unpack228.unpack.unpack230, 8
  br i1 %min.iters.check, label %.lr.ph.i.preheader263, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.i.preheader
  %n.vec = and i64 %.unpack228.unpack.unpack230, -8
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %vector.ph ], [ %29, %vector.body ]
  %vec.phi261 = phi <4 x i32> [ <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %vector.ph ], [ %30, %vector.body ]
  %26 = shl i64 %index, 2
  %27 = getelementptr i8, ptr %.unpack221, i64 %26
  %wide.load = load <4 x i32>, ptr %27, align 4, !tbaa !3
  %28 = getelementptr i32, ptr %27, i64 4
  %wide.load262 = load <4 x i32>, ptr %28, align 4, !tbaa !3
  %29 = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %wide.load, <4 x i32> %vec.phi)
  %30 = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %wide.load262, <4 x i32> %vec.phi261)
  %index.next = add nuw i64 %index, 8
  %31 = icmp eq i64 %index.next, %n.vec
  br i1 %31, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %rdx.minmax.select = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %29, <4 x i32> %30)
  %32 = call i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %rdx.minmax.select)
  %cmp.n = icmp eq i64 %.unpack228.unpack.unpack230, %n.vec
  br i1 %cmp.n, label %_FortranAMaxvalInteger4x1_contract_simplified.exit, label %.lr.ph.i.preheader263

.lr.ph.i.preheader263:                            ; preds = %.lr.ph.i.preheader, %middle.block
  %.ph = phi i32 [ -2147483648, %.lr.ph.i.preheader ], [ %32, %middle.block ]
  %.ph264 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader263, %.lr.ph.i
  %33 = phi i32 [ %38, %.lr.ph.i ], [ %.ph, %.lr.ph.i.preheader263 ]
  %34 = phi i64 [ %39, %.lr.ph.i ], [ %.ph264, %.lr.ph.i.preheader263 ]
  %35 = shl i64 %34, 2
  %36 = getelementptr i8, ptr %.unpack221, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !3
  %38 = call i32 @llvm.smax.i32(i32 %37, i32 %33)
  %39 = add nuw nsw i64 %34, 1
  %exitcond.not.i = icmp eq i64 %39, %.unpack228.unpack.unpack230
  br i1 %exitcond.not.i, label %_FortranAMaxvalInteger4x1_contract_simplified.exit, label %.lr.ph.i, !llvm.loop !12

_FortranAMaxvalInteger4x1_contract_simplified.exit: ; preds = %.lr.ph.i, %middle.block, %._crit_edge
  %.lcssa.i = phi i32 [ -2147483648, %._crit_edge ], [ %32, %middle.block ], [ %38, %.lr.ph.i ]
  %40 = add i32 %24, 1
  %41 = sub i32 %40, %.lcssa.i
  %spec.store.select = call i32 @llvm.smax.i32(i32 %41, i32 0)
  %42 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.db55e11ab4d60c05287437c9d2d61bc4, i32 22)
  %43 = call i1 @_FortranAioOutputInteger32(ptr %42, i32 %spec.store.select)
  %44 = 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 i32 @_FortranAMinvalInteger4(ptr, ptr, i32, i32, ptr) local_unnamed_addr

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

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i32 @llvm.vector.reduce.smax.v4i32(<4 x i32>) #3

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind 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}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !11, !10}
