program main
Implicit None
	integer i,N,M,count,Lmax,Rmin
	integer,allocatable :: L(:),R(:)
	
	read(5,*) N,M
	allocate(L(M),R(M))
	Lmax=0	;Rmin=N
	
	do i=1,M
		read(5,*) L(i),R(i)
		if(L(i)>Lmax)	Lmax=L(i)
		if(R(i)<Rmin)	Rmin=R(i)
	end do
	
	count=Rmin-Lmax+1
	if(count<0)	count=0
	write(6,'(i0)') count

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"

@_QFEl.0 = internal unnamed_addr global ptr null
@_QFEr.0 = internal unnamed_addr global ptr null
@_QQcl.5ce2d155622203cb09ca0f7efb858154 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_4230/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

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 5, ptr nonnull @_QQcl.5ce2d155622203cb09ca0f7efb858154, i32 6)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %1, i32 4)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %7 = load i32, ptr %1, align 4, !tbaa !3
  %8 = call i32 @llvm.smax.i32(i32 %7, i32 0)
  %9 = zext i32 %8 to i64
  %10 = shl nuw nsw i64 %9, 2
  %11 = call ptr @malloc(i64 %10)
  store ptr %11, ptr @_QFEl.0, align 8, !tbaa !7
  %12 = call ptr @malloc(i64 %10)
  store ptr %12, ptr @_QFEr.0, align 8, !tbaa !7
  %13 = load i32, ptr %2, align 4, !tbaa !3
  %14 = icmp sgt i32 %7, 0
  br i1 %14, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %15 = zext i32 %7 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 ]
  %.0251 = phi i32 [ %13, %.lr.ph.preheader ], [ %.1, %.lr.ph ]
  %.0180250 = phi i32 [ 0, %.lr.ph.preheader ], [ %spec.select, %.lr.ph ]
  %16 = call ptr @_FortranAioBeginExternalListInput(i32 5, ptr nonnull @_QQcl.5ce2d155622203cb09ca0f7efb858154, i32 11)
  %.unpack = load ptr, ptr @_QFEl.0, align 8, !tbaa !7
  %17 = add nsw i64 %indvars.iv, -1
  %18 = getelementptr i32, ptr %.unpack, i64 %17
  %19 = call i1 @_FortranAioInputInteger(ptr %16, ptr %18, i32 4)
  %.unpack214 = load ptr, ptr @_QFEr.0, align 8, !tbaa !7
  %20 = add nsw i64 %indvars.iv, -1
  %21 = getelementptr i32, ptr %.unpack214, i64 %20
  %22 = call i1 @_FortranAioInputInteger(ptr %16, ptr %21, i32 4)
  %23 = call i32 @_FortranAioEndIoStatement(ptr %16)
  %.unpack226 = load ptr, ptr @_QFEl.0, align 8, !tbaa !7
  %24 = add nsw i64 %indvars.iv, -1
  %25 = getelementptr i32, ptr %.unpack226, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !3
  %spec.select = call i32 @llvm.smax.i32(i32 %26, i32 %.0180250)
  %.unpack238 = load ptr, ptr @_QFEr.0, align 8, !tbaa !7
  %27 = add nsw i64 %indvars.iv, -1
  %28 = getelementptr i32, ptr %.unpack238, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !3
  %.1 = call i32 @llvm.smin.i32(i32 %29, i32 %.0251)
  %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
  %30 = sub i32 1, %spec.select
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %.0180.lcssa = phi i32 [ 1, %0 ], [ %30, %._crit_edge.loopexit ]
  %.0.lcssa = phi i32 [ %13, %0 ], [ %.1, %._crit_edge.loopexit ]
  %31 = add i32 %.0180.lcssa, %.0.lcssa
  %spec.store.select = call i32 @llvm.smax.i32(i32 %31, i32 0)
  %32 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 6, ptr nonnull @_QQcl.5ce2d155622203cb09ca0f7efb858154, i32 18)
  %33 = call i1 @_FortranAioOutputInteger32(ptr %32, i32 %spec.store.select)
  %34 = call i32 @_FortranAioEndIoStatement(ptr %32)
  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 @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, 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 nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.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}
