      PROGRAM piyo
      IMPLICIT NONE
      integer(16) :: n,m,lMax,rMin,i
      integer(16),allocatable :: l(:),r(:)
      
      read*,n,m
      allocate( l(m),r(m) )
      do i = 1,m
        read*,l(i),r(i)
      end do
      
      
      
      rMin = minval( r )
      lMax = maxval( l )
      
      
      print*,max(0,rMin - lMax + 1)
      
      
      
      
      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"

@_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.da1ed7a0e5b3aafa5f55d5ba112bea50 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_4232/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 i128, align 8
  %3 = alloca i128, align 8
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.da1ed7a0e5b3aafa5f55d5ba112bea50, i32 6)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 16)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 16)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %8 = load i128, ptr %2, align 8, !tbaa !3
  %9 = trunc i128 %8 to i64
  %10 = call i64 @llvm.smax.i64(i64 %9, i64 0)
  %11 = shl i64 %10, 4
  %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 i64 %9, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %15 = phi i64 [ %24, %.lr.ph ], [ 1, %0 ]
  %16 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.da1ed7a0e5b3aafa5f55d5ba112bea50, i32 9)
  %.unpack233 = load ptr, ptr @_QFEl.0, align 8, !tbaa !7
  %17 = add i64 %15, -1
  %18 = getelementptr i128, ptr %.unpack233, i64 %17
  %19 = call i1 @_FortranAioInputInteger(ptr %16, ptr %18, i32 16)
  %.unpack245 = load ptr, ptr @_QFEr.0, align 8, !tbaa !7
  %20 = add i64 %15, -1
  %21 = getelementptr i128, ptr %.unpack245, i64 %20
  %22 = call i1 @_FortranAioInputInteger(ptr %16, ptr %21, i32 16)
  %23 = call i32 @_FortranAioEndIoStatement(ptr %16)
  %24 = add nuw i64 %15, 1
  %exitcond.not = icmp eq i64 %15, %9
  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 16, 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 11, 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 16, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %25 = call i128 @_FortranAMinvalInteger16(ptr nonnull %1, ptr nonnull @_QQcl.da1ed7a0e5b3aafa5f55d5ba112bea50, i32 14, 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
  %26 = icmp sgt i64 %.unpack228.unpack.unpack230, 0
  br i1 %26, label %.lr.ph.i.preheader, label %_FortranAMaxvalInteger16x1_contract_simplified.exit

.lr.ph.i.preheader:                               ; preds = %._crit_edge
  %xtraiter = and i64 %.unpack228.unpack.unpack230, 1
  %27 = icmp eq i64 %.unpack228.unpack.unpack230, 1
  br i1 %27, label %_FortranAMaxvalInteger16x1_contract_simplified.exit.loopexit.unr-lcssa, label %.lr.ph.i.preheader.new

.lr.ph.i.preheader.new:                           ; preds = %.lr.ph.i.preheader
  %unroll_iter = and i64 %.unpack228.unpack.unpack230, -2
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i, %.lr.ph.i.preheader.new
  %28 = phi i128 [ 0, %.lr.ph.i.preheader.new ], [ %38, %.lr.ph.i ]
  %29 = phi i64 [ 0, %.lr.ph.i.preheader.new ], [ %39, %.lr.ph.i ]
  %niter = phi i64 [ 0, %.lr.ph.i.preheader.new ], [ %niter.next.1, %.lr.ph.i ]
  %30 = shl i64 %29, 4
  %31 = getelementptr i8, ptr %.unpack221, i64 %30
  %32 = load i128, ptr %31, align 8, !tbaa !3
  %33 = call i128 @llvm.smax.i128(i128 %32, i128 %28)
  %34 = shl i64 %29, 4
  %35 = or i64 %34, 16
  %36 = getelementptr i8, ptr %.unpack221, i64 %35
  %37 = load i128, ptr %36, align 8, !tbaa !3
  %38 = call i128 @llvm.smax.i128(i128 %37, i128 %33)
  %39 = add nuw nsw i64 %29, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %_FortranAMaxvalInteger16x1_contract_simplified.exit.loopexit.unr-lcssa.loopexit, label %.lr.ph.i

_FortranAMaxvalInteger16x1_contract_simplified.exit.loopexit.unr-lcssa.loopexit: ; preds = %.lr.ph.i
  %40 = shl i64 %39, 4
  br label %_FortranAMaxvalInteger16x1_contract_simplified.exit.loopexit.unr-lcssa

_FortranAMaxvalInteger16x1_contract_simplified.exit.loopexit.unr-lcssa: ; preds = %_FortranAMaxvalInteger16x1_contract_simplified.exit.loopexit.unr-lcssa.loopexit, %.lr.ph.i.preheader
  %.lcssa.ph = phi i128 [ undef, %.lr.ph.i.preheader ], [ %38, %_FortranAMaxvalInteger16x1_contract_simplified.exit.loopexit.unr-lcssa.loopexit ]
  %.unr = phi i128 [ 0, %.lr.ph.i.preheader ], [ %38, %_FortranAMaxvalInteger16x1_contract_simplified.exit.loopexit.unr-lcssa.loopexit ]
  %.unr260 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %40, %_FortranAMaxvalInteger16x1_contract_simplified.exit.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %_FortranAMaxvalInteger16x1_contract_simplified.exit, label %.lr.ph.i.epil

.lr.ph.i.epil:                                    ; preds = %_FortranAMaxvalInteger16x1_contract_simplified.exit.loopexit.unr-lcssa
  %41 = getelementptr i8, ptr %.unpack221, i64 %.unr260
  %42 = load i128, ptr %41, align 8, !tbaa !3
  %43 = call i128 @llvm.smax.i128(i128 %42, i128 %.unr)
  br label %_FortranAMaxvalInteger16x1_contract_simplified.exit

_FortranAMaxvalInteger16x1_contract_simplified.exit: ; preds = %.lr.ph.i.epil, %_FortranAMaxvalInteger16x1_contract_simplified.exit.loopexit.unr-lcssa, %._crit_edge
  %.lcssa.i = phi i128 [ 0, %._crit_edge ], [ %.lcssa.ph, %_FortranAMaxvalInteger16x1_contract_simplified.exit.loopexit.unr-lcssa ], [ %43, %.lr.ph.i.epil ]
  %44 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.da1ed7a0e5b3aafa5f55d5ba112bea50, i32 18)
  %45 = add i128 %25, 1
  %46 = sub i128 %45, %.lcssa.i
  %47 = call i128 @llvm.smax.i128(i128 %46, i128 0)
  %48 = call i1 @_FortranAioOutputInteger128(ptr %44, i128 %47)
  %49 = call i32 @_FortranAioEndIoStatement(ptr %44)
  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 i128 @_FortranAMinvalInteger16(ptr, ptr, i32, i32, ptr) local_unnamed_addr

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

declare i1 @_FortranAioOutputInteger128(ptr, i128) local_unnamed_addr

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

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

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

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