PROGRAM ATCODER

implicit none
integer :: i,j,n,m,index=1,dp,dp2,check,count=0
integer,allocatable :: l(:),r(:)

read*, n,m 
allocate(l(m),r(m))
do i = 1, m, 1
  read*, l(i),r(i)
end do

dp = 1
dp2 = n
do i = 1, m, 1
  call chmax(dp,l(i))
  call chmin(dp2,r(i))
end do

if ( dp2 - dp < 0 ) then
  print'(i0)', 0
else
  print'(i0)', dp2 - dp + 1
end if

contains
  subroutine chmax(dp,x)
  implicit none
  integer :: dp, x

  if (dp < x) then
  	dp = x
  	return
  end if

  end subroutine

  subroutine chmin(dp,x)
  implicit none
  integer :: dp, x

  if (dp > x) then
  	dp = x
  	return
  end if

  end subroutine

END PROGRAM ATCODER
; 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.bf3c0955d46d8899a7c18e6c82d4843e = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_4234/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 -1, ptr nonnull @_QQcl.bf3c0955d46d8899a7c18e6c82d4843e, i32 7)
  %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 = icmp sgt i32 %7, 0
  br i1 %13, label %.lr.ph.preheader, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %0
  %14 = load i32, ptr %2, align 4, !tbaa !3
  br label %._crit_edge208

.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 ]
  %16 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.bf3c0955d46d8899a7c18e6c82d4843e, i32 10)
  %.unpack175 = load ptr, ptr @_QFEl.0, align 8, !tbaa !7
  %17 = add nsw i64 %indvars.iv, -1
  %18 = getelementptr i32, ptr %.unpack175, i64 %17
  %19 = call i1 @_FortranAioInputInteger(ptr %16, ptr %18, i32 4)
  %.unpack187 = load ptr, ptr @_QFEr.0, align 8, !tbaa !7
  %20 = add nsw i64 %indvars.iv, -1
  %21 = getelementptr i32, ptr %.unpack187, 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, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  %.pre = load i32, ptr %1, align 4, !tbaa !3
  %24 = load i32, ptr %2, align 4, !tbaa !3
  %25 = icmp sgt i32 %.pre, 0
  br i1 %25, label %_QFPchmax.exit.lr.ph, label %._crit_edge208

_QFPchmax.exit.lr.ph:                             ; preds = %._crit_edge
  %26 = zext i32 %.pre to i64
  %.unpack = load ptr, ptr @_QFEl.0, align 8, !tbaa !7
  %.unpack163 = load ptr, ptr @_QFEr.0, align 8, !tbaa !7
  %min.iters.check = icmp ult i32 %.pre, 8
  br i1 %min.iters.check, label %_QFPchmax.exit.preheader, label %vector.ph

vector.ph:                                        ; preds = %_QFPchmax.exit.lr.ph
  %n.vec = and i64 %26, 4294967288
  %ind.end = or i64 %n.vec, 1
  %minmax.ident.splatinsert = insertelement <4 x i32> poison, i32 %24, i64 0
  %minmax.ident.splat = shufflevector <4 x i32> %minmax.ident.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  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> [ %minmax.ident.splat, %vector.ph ], [ %33, %vector.body ]
  %vec.phi215 = phi <4 x i32> [ %minmax.ident.splat, %vector.ph ], [ %34, %vector.body ]
  %vec.phi216 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %vector.ph ], [ %29, %vector.body ]
  %vec.phi217 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %vector.ph ], [ %30, %vector.body ]
  %27 = getelementptr i32, ptr %.unpack, i64 %index
  %wide.load = load <4 x i32>, ptr %27, align 4, !tbaa !3
  %28 = getelementptr i32, ptr %27, i64 4
  %wide.load218 = load <4 x i32>, ptr %28, align 4, !tbaa !3
  %29 = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %vec.phi216, <4 x i32> %wide.load)
  %30 = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %vec.phi217, <4 x i32> %wide.load218)
  %31 = getelementptr i32, ptr %.unpack163, i64 %index
  %wide.load219 = load <4 x i32>, ptr %31, align 4, !tbaa !3
  %32 = getelementptr i32, ptr %31, i64 4
  %wide.load220 = load <4 x i32>, ptr %32, align 4, !tbaa !3
  %33 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %vec.phi, <4 x i32> %wide.load219)
  %34 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %vec.phi215, <4 x i32> %wide.load220)
  %index.next = add nuw i64 %index, 8
  %35 = icmp eq i64 %index.next, %n.vec
  br i1 %35, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %rdx.minmax.select222 = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %29, <4 x i32> %30)
  %36 = call i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %rdx.minmax.select222)
  %rdx.minmax.select = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %33, <4 x i32> %34)
  %37 = call i32 @llvm.vector.reduce.smin.v4i32(<4 x i32> %rdx.minmax.select)
  %cmp.n = icmp eq i64 %n.vec, %26
  br i1 %cmp.n, label %._crit_edge208, label %_QFPchmax.exit.preheader

_QFPchmax.exit.preheader:                         ; preds = %_QFPchmax.exit.lr.ph, %middle.block
  %indvars.iv211.ph = phi i64 [ 1, %_QFPchmax.exit.lr.ph ], [ %ind.end, %middle.block ]
  %.0207.ph = phi i32 [ %24, %_QFPchmax.exit.lr.ph ], [ %37, %middle.block ]
  %.0204206.ph = phi i32 [ 1, %_QFPchmax.exit.lr.ph ], [ %36, %middle.block ]
  br label %_QFPchmax.exit

_QFPchmax.exit:                                   ; preds = %_QFPchmax.exit.preheader, %_QFPchmax.exit
  %indvars.iv211 = phi i64 [ %indvars.iv.next212, %_QFPchmax.exit ], [ %indvars.iv211.ph, %_QFPchmax.exit.preheader ]
  %.0207 = phi i32 [ %.1, %_QFPchmax.exit ], [ %.0207.ph, %_QFPchmax.exit.preheader ]
  %.0204206 = phi i32 [ %spec.select, %_QFPchmax.exit ], [ %.0204206.ph, %_QFPchmax.exit.preheader ]
  %38 = add i64 %indvars.iv211, -1
  %39 = getelementptr i32, ptr %.unpack, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !3
  %spec.select = call i32 @llvm.smax.i32(i32 %.0204206, i32 %40)
  %41 = add i64 %indvars.iv211, -1
  %42 = getelementptr i32, ptr %.unpack163, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !3
  %.1 = call i32 @llvm.smin.i32(i32 %.0207, i32 %43)
  %indvars.iv.next212 = add nuw nsw i64 %indvars.iv211, 1
  %exitcond214.not = icmp eq i64 %indvars.iv211, %26
  br i1 %exitcond214.not, label %._crit_edge208, label %_QFPchmax.exit, !llvm.loop !12

._crit_edge208:                                   ; preds = %_QFPchmax.exit, %middle.block, %._crit_edge.thread, %._crit_edge
  %.0204.lcssa = phi i32 [ 1, %._crit_edge ], [ 1, %._crit_edge.thread ], [ %36, %middle.block ], [ %spec.select, %_QFPchmax.exit ]
  %.0.lcssa = phi i32 [ %24, %._crit_edge ], [ %14, %._crit_edge.thread ], [ %37, %middle.block ], [ %.1, %_QFPchmax.exit ]
  %44 = sub i32 %.0.lcssa, %.0204.lcssa
  %45 = icmp slt i32 %44, 0
  br i1 %45, label %46, label %49

46:                                               ; preds = %._crit_edge208
  %47 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.bf3c0955d46d8899a7c18e6c82d4843e, i32 21)
  %48 = call i1 @_FortranAioOutputInteger32(ptr %47, i32 0)
  br label %53

49:                                               ; preds = %._crit_edge208
  %50 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.bf3c0955d46d8899a7c18e6c82d4843e, i32 23)
  %51 = add nuw i32 %44, 1
  %52 = call i1 @_FortranAioOutputInteger32(ptr %50, i32 %51)
  br label %53

53:                                               ; preds = %46, %49
  %.sink = phi ptr [ %47, %46 ], [ %50, %49 ]
  %54 = call i32 @_FortranAioEndIoStatement(ptr %.sink)
  ret void
}

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite)
define void @_QFPchmax(ptr nocapture %0, ptr nocapture readonly %1) local_unnamed_addr #1 {
  %3 = load i32, ptr %0, align 4, !tbaa !3
  %4 = load i32, ptr %1, align 4, !tbaa !3
  %5 = icmp slt i32 %3, %4
  br i1 %5, label %6, label %7

6:                                                ; preds = %2
  store i32 %4, ptr %0, align 4, !tbaa !3
  br label %7

7:                                                ; preds = %6, %2
  ret void
}

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite)
define void @_QFPchmin(ptr nocapture %0, ptr nocapture readonly %1) local_unnamed_addr #1 {
  %3 = load i32, ptr %0, align 4, !tbaa !3
  %4 = load i32, ptr %1, align 4, !tbaa !3
  %5 = icmp sgt i32 %3, %4
  br i1 %5, label %6, label %7

6:                                                ; preds = %2
  store i32 %4, ptr %0, align 4, !tbaa !3
  br label %7

7:                                                ; preds = %6, %2
  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) #2

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

; 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 speculatable willreturn memory(none)
declare <4 x i32> @llvm.smin.v4i32(<4 x i32>, <4 x i32>) #2

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

; 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 nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) }
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}
