integer N,M
integer(16),allocatable::a(:),b(:),c(:)
integer(16),allocatable::dist(:)
integer(16) ans

logical,allocatable::negative(:)


read*,N,M
allocate( a(M),b(M),c(M) )
do i=1,M
  read*,a(i),b(i),c(i)
  c(i)=-c(i)
end do

allocate(dist(N))
dist=huge(a(J))/2
dist(1)=0
do i=1,N-1
  do j=1,M
    if(dist(a(j))==huge(a(j))/2)cycle
    if (dist(b(j)) > dist(a(j))+c(j) )dist(b(j))= dist(a(j))+ c(j)
  end do
end do
ans=dist(N)

allocate(negative(N))
negative=.false.
do i=1,N
  do j=1,M
   if (dist(a(j)) == huge(a(j))/2)cycle
   if (dist(b(j)) > dist(a(j)) + c(j) )then
     dist(b(j)) = dist(a(j)) + c(j)
     negative(b(j)) = .true.
   endif
   if (negative(a(j)) ) negative(b(j)) =.true.
  end do
end do

if(negative(N))then
  print"(A)","inf"
else
  print"(i0)",-ans
end if
end
; 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"

@_QFEa.0 = internal unnamed_addr global ptr null
@_QFEb.0 = internal unnamed_addr global ptr null
@_QFEc.0 = internal unnamed_addr global ptr null
@_QFEdist.0 = internal unnamed_addr global ptr null
@_QFEdist.7 = internal unnamed_addr global i64 1
@_QFEnegative.0 = internal unnamed_addr global ptr null
@_QFEnegative.7 = internal unnamed_addr global i64 1
@_QQcl.c693633e7ad6bb456b53701034d4050b = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_7302/source.f\00"
@_QQcl.16373402fa3425c6e46827601abb88fa = linkonce constant [76 x i8] c"array left hand side must be allocated when the right hand side is a scalar\00"
@_QQcl.284129 = linkonce constant [3 x i8] c"(A)"
@_QQcl.696E66 = linkonce constant [3 x i8] c"inf"
@_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.c693633e7ad6bb456b53701034d4050b, i32 9)
  %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, 4
  %11 = call ptr @malloc(i64 %10)
  store ptr %11, ptr @_QFEa.0, align 8, !tbaa !7
  %12 = call ptr @malloc(i64 %10)
  store ptr %12, ptr @_QFEb.0, align 8, !tbaa !7
  %13 = call ptr @malloc(i64 %10)
  store ptr %13, ptr @_QFEc.0, align 8, !tbaa !7
  %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 ]
  %16 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.c693633e7ad6bb456b53701034d4050b, i32 12)
  %.unpack1302 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %17 = add nsw i64 %indvars.iv, -1
  %18 = getelementptr i128, ptr %.unpack1302, i64 %17
  %19 = call i1 @_FortranAioInputInteger(ptr %16, ptr %18, i32 16)
  %.unpack1314 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %20 = add nsw i64 %indvars.iv, -1
  %21 = getelementptr i128, ptr %.unpack1314, i64 %20
  %22 = call i1 @_FortranAioInputInteger(ptr %16, ptr %21, i32 16)
  %.unpack1326 = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  %23 = add nsw i64 %indvars.iv, -1
  %24 = getelementptr i128, ptr %.unpack1326, i64 %23
  %25 = call i1 @_FortranAioInputInteger(ptr %16, ptr %24, i32 16)
  %26 = call i32 @_FortranAioEndIoStatement(ptr %16)
  %.unpack1338 = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  %27 = add nsw i64 %indvars.iv, -1
  %28 = getelementptr i128, ptr %.unpack1338, i64 %27
  %29 = load i128, ptr %28, align 8, !tbaa !3
  %30 = sub i128 0, %29
  store i128 %30, ptr %28, align 8, !tbaa !3
  %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, %0
  %31 = load i32, ptr %2, align 4, !tbaa !3
  %32 = call i32 @llvm.smax.i32(i32 %31, i32 0)
  %33 = zext i32 %32 to i64
  %34 = shl nuw nsw i64 %33, 4
  %35 = call ptr @malloc(i64 %34)
  store ptr %35, ptr @_QFEdist.0, align 8, !tbaa !7
  store i64 1, ptr @_QFEdist.7, align 8, !tbaa !7
  %.not = icmp eq ptr %35, null
  br i1 %.not, label %42, label %.preheader1351

.preheader1351:                                   ; preds = %._crit_edge
  %.not1367 = icmp slt i32 %31, 1
  br i1 %.not1367, label %.loopexit1352, label %.lr.ph1353

.lr.ph1353:                                       ; preds = %.preheader1351, %.lr.ph1353
  %36 = phi i64 [ %40, %.lr.ph1353 ], [ %33, %.preheader1351 ]
  %37 = phi i64 [ %38, %.lr.ph1353 ], [ 0, %.preheader1351 ]
  %38 = add nuw nsw i64 %37, 1
  %39 = getelementptr i128, ptr %35, i64 %37
  store i128 85070591730234615865843651857942052863, ptr %39, align 8, !tbaa !3
  %40 = add nsw i64 %36, -1
  %41 = icmp ugt i64 %36, 1
  br i1 %41, label %.lr.ph1353, label %.loopexit1352

42:                                               ; preds = %._crit_edge
  %43 = call {} @_FortranAReportFatalUserError(ptr nonnull @_QQcl.16373402fa3425c6e46827601abb88fa, ptr nonnull @_QQcl.c693633e7ad6bb456b53701034d4050b, i32 17)
  %.unpack1288.unpack.unpack = load i64, ptr @_QFEdist.7, align 8, !tbaa !7
  %44 = icmp slt i32 %31, 1
  %45 = select i1 %44, i64 1, i64 %.unpack1288.unpack.unpack
  store ptr null, ptr @_QFEdist.0, align 8, !tbaa !7
  store i64 %45, ptr @_QFEdist.7, align 8, !tbaa !7
  %.pre = load i32, ptr %2, align 4, !tbaa !3
  br label %.loopexit1352

.loopexit1352:                                    ; preds = %.lr.ph1353, %.preheader1351, %42
  %46 = phi i32 [ %31, %.preheader1351 ], [ %.pre, %42 ], [ %31, %.lr.ph1353 ]
  %.unpack1061.unpack.unpack = phi i64 [ 1, %.preheader1351 ], [ %45, %42 ], [ 1, %.lr.ph1353 ]
  %47 = sub i64 1, %.unpack1061.unpack.unpack
  %48 = getelementptr i128, ptr %35, i64 %47
  store i128 0, ptr %48, align 8, !tbaa !3
  %49 = add i32 %46, -1
  %50 = icmp sgt i32 %49, 0
  br i1 %50, label %.lr.ph1358, label %._crit_edge1359

.lr.ph1358:                                       ; preds = %.loopexit1352
  %51 = load i32, ptr %1, align 4, !tbaa !3
  %52 = icmp sgt i32 %51, 0
  %.unpack1244 = load ptr, ptr @_QFEa.0, align 8
  %.unpack1257 = load ptr, ptr @_QFEb.0, align 8
  %.unpack1269 = load ptr, ptr @_QFEc.0, align 8
  br i1 %52, label %.lr.ph1355.us.preheader, label %._crit_edge1359

.lr.ph1355.us.preheader:                          ; preds = %.lr.ph1358
  %53 = zext i32 %51 to i64
  %54 = zext i32 %49 to i64
  br label %.lr.ph1355.us

.lr.ph1355.us:                                    ; preds = %.lr.ph1355.us.preheader, %._crit_edge1356.us
  %55 = phi i64 [ %79, %._crit_edge1356.us ], [ %54, %.lr.ph1355.us.preheader ]
  br label %56

56:                                               ; preds = %.lr.ph1355.us, %78
  %indvars.iv1371 = phi i64 [ 1, %.lr.ph1355.us ], [ %indvars.iv.next1372, %78 ]
  %57 = add nsw i64 %indvars.iv1371, -1
  %58 = getelementptr i128, ptr %.unpack1244, i64 %57
  %59 = load i128, ptr %58, align 8, !tbaa !3
  %60 = trunc i128 %59 to i64
  %61 = sub i64 %60, %.unpack1061.unpack.unpack
  %62 = getelementptr i128, ptr %35, i64 %61
  %63 = load i128, ptr %62, align 8, !tbaa !3
  %.not1256.us = icmp eq i128 %63, 85070591730234615865843651857942052863
  br i1 %.not1256.us, label %78, label %64

64:                                               ; preds = %56
  %65 = add nsw i64 %indvars.iv1371, -1
  %66 = getelementptr i128, ptr %.unpack1257, i64 %65
  %67 = load i128, ptr %66, align 8, !tbaa !3
  %68 = trunc i128 %67 to i64
  %69 = sub i64 %68, %.unpack1061.unpack.unpack
  %70 = getelementptr i128, ptr %35, i64 %69
  %71 = load i128, ptr %70, align 8, !tbaa !3
  %72 = add nsw i64 %indvars.iv1371, -1
  %73 = getelementptr i128, ptr %.unpack1269, i64 %72
  %74 = load i128, ptr %73, align 8, !tbaa !3
  %75 = add i128 %74, %63
  %76 = icmp sgt i128 %71, %75
  br i1 %76, label %77, label %78

77:                                               ; preds = %64
  store i128 %75, ptr %70, align 8, !tbaa !3
  br label %78

78:                                               ; preds = %77, %64, %56
  %indvars.iv.next1372 = add nuw nsw i64 %indvars.iv1371, 1
  %exitcond1374.not = icmp eq i64 %indvars.iv1371, %53
  br i1 %exitcond1374.not, label %._crit_edge1356.us, label %56

._crit_edge1356.us:                               ; preds = %78
  %79 = add nsw i64 %55, -1
  %80 = icmp sgt i64 %55, 1
  br i1 %80, label %.lr.ph1355.us, label %._crit_edge1359

._crit_edge1359:                                  ; preds = %._crit_edge1356.us, %.lr.ph1358, %.loopexit1352
  %81 = sext i32 %46 to i64
  %82 = sub i64 %81, %.unpack1061.unpack.unpack
  %83 = getelementptr i128, ptr %35, i64 %82
  %84 = load i128, ptr %83, align 8, !tbaa !3
  %85 = call i64 @llvm.smax.i64(i64 %81, i64 0)
  %86 = shl nuw nsw i64 %85, 2
  %87 = call ptr @malloc(i64 %86)
  store ptr %87, ptr @_QFEnegative.0, align 8, !tbaa !7
  store i64 1, ptr @_QFEnegative.7, align 8, !tbaa !7
  %.not1087 = icmp eq ptr %87, null
  br i1 %.not1087, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %._crit_edge1359
  %.not1368 = icmp slt i32 %46, 1
  br i1 %.not1368, label %.loopexit.._crit_edge1366_crit_edge, label %.loopexit.thread

.loopexit.thread:                                 ; preds = %.preheader
  call void @llvm.memset.p0.i64(ptr nonnull align 4 %87, i8 0, i64 %86, i1 false), !tbaa !3
  br label %.lr.ph1365

.loopexit:                                        ; preds = %._crit_edge1359
  %88 = call {} @_FortranAReportFatalUserError(ptr nonnull @_QQcl.16373402fa3425c6e46827601abb88fa, ptr nonnull @_QQcl.c693633e7ad6bb456b53701034d4050b, i32 28)
  %.unpack1218.unpack.unpack = load i64, ptr @_QFEnegative.7, align 8, !tbaa !7
  %89 = icmp slt i32 %46, 1
  %90 = select i1 %89, i64 1, i64 %.unpack1218.unpack.unpack
  store i64 %90, ptr @_QFEnegative.7, align 8, !tbaa !7
  %.pre1381 = load i32, ptr %2, align 4, !tbaa !3
  %91 = icmp sgt i32 %.pre1381, 0
  br i1 %91, label %.lr.ph1365, label %.loopexit.._crit_edge1366_crit_edge

.loopexit.._crit_edge1366_crit_edge:              ; preds = %.preheader, %.loopexit
  %92 = phi i32 [ %.pre1381, %.loopexit ], [ %46, %.preheader ]
  %.unpack1095.unpack.unpack1398 = phi i64 [ %90, %.loopexit ], [ 1, %.preheader ]
  %.pre1387 = sext i32 %92 to i64
  br label %._crit_edge1366

.lr.ph1365:                                       ; preds = %.loopexit.thread, %.loopexit
  %93 = phi i32 [ %46, %.loopexit.thread ], [ %.pre1381, %.loopexit ]
  %.unpack1095.unpack.unpack1391 = phi i64 [ 1, %.loopexit.thread ], [ %90, %.loopexit ]
  %94 = zext i32 %93 to i64
  %.unpack1101 = load ptr, ptr @_QFEdist.0, align 8
  %.unpack1108.unpack.unpack = load i64, ptr @_QFEdist.7, align 8
  %.unpack1113 = load ptr, ptr @_QFEa.0, align 8
  %.unpack1126 = load ptr, ptr @_QFEb.0, align 8
  %.unpack1138 = load ptr, ptr @_QFEc.0, align 8
  %.pre1384 = load i32, ptr %1, align 4, !tbaa !3
  %95 = icmp sgt i32 %.pre1384, 0
  %96 = zext i32 %.pre1384 to i64
  br label %97

97:                                               ; preds = %.lr.ph1365, %._crit_edge1363
  %98 = phi i64 [ %94, %.lr.ph1365 ], [ %134, %._crit_edge1363 ]
  br i1 %95, label %.lr.ph1362, label %._crit_edge1363

.lr.ph1362:                                       ; preds = %97, %133
  %indvars.iv1375 = phi i64 [ %indvars.iv.next1376, %133 ], [ 1, %97 ]
  %99 = add nsw i64 %indvars.iv1375, -1
  %100 = getelementptr i128, ptr %.unpack1113, i64 %99
  %101 = load i128, ptr %100, align 8, !tbaa !3
  %102 = trunc i128 %101 to i64
  %103 = sub i64 %102, %.unpack1108.unpack.unpack
  %104 = getelementptr i128, ptr %.unpack1101, i64 %103
  %105 = load i128, ptr %104, align 8, !tbaa !3
  %.not1125 = icmp eq i128 %105, 85070591730234615865843651857942052863
  br i1 %.not1125, label %133, label %106

106:                                              ; preds = %.lr.ph1362
  %107 = add nsw i64 %indvars.iv1375, -1
  %108 = getelementptr i128, ptr %.unpack1126, i64 %107
  %109 = load i128, ptr %108, align 8, !tbaa !3
  %110 = trunc i128 %109 to i64
  %111 = sub i64 %110, %.unpack1108.unpack.unpack
  %112 = getelementptr i128, ptr %.unpack1101, i64 %111
  %113 = load i128, ptr %112, align 8, !tbaa !3
  %114 = add nsw i64 %indvars.iv1375, -1
  %115 = getelementptr i128, ptr %.unpack1138, i64 %114
  %116 = load i128, ptr %115, align 8, !tbaa !3
  %117 = add i128 %116, %105
  %118 = icmp sgt i128 %113, %117
  br i1 %118, label %119, label %124

119:                                              ; preds = %106
  store i128 %117, ptr %112, align 8, !tbaa !3
  %120 = load i128, ptr %108, align 8, !tbaa !3
  %121 = trunc i128 %120 to i64
  %122 = sub i64 %121, %.unpack1095.unpack.unpack1391
  %123 = getelementptr i32, ptr %87, i64 %122
  store i32 1, ptr %123, align 4, !tbaa !3
  %.pre1385 = load i128, ptr %100, align 8, !tbaa !3
  %.pre1386 = trunc i128 %.pre1385 to i64
  br label %124

124:                                              ; preds = %119, %106
  %.pre-phi = phi i64 [ %.pre1386, %119 ], [ %102, %106 ]
  %125 = sub i64 %.pre-phi, %.unpack1095.unpack.unpack1391
  %126 = getelementptr i32, ptr %87, i64 %125
  %127 = load i32, ptr %126, align 4, !tbaa !3
  %.not1174 = icmp eq i32 %127, 0
  br i1 %.not1174, label %133, label %128

128:                                              ; preds = %124
  %129 = load i128, ptr %108, align 8, !tbaa !3
  %130 = trunc i128 %129 to i64
  %131 = sub i64 %130, %.unpack1095.unpack.unpack1391
  %132 = getelementptr i32, ptr %87, i64 %131
  store i32 1, ptr %132, align 4, !tbaa !3
  br label %133

133:                                              ; preds = %128, %124, %.lr.ph1362
  %indvars.iv.next1376 = add nuw nsw i64 %indvars.iv1375, 1
  %exitcond1378.not = icmp eq i64 %indvars.iv1375, %96
  br i1 %exitcond1378.not, label %._crit_edge1363, label %.lr.ph1362

._crit_edge1363:                                  ; preds = %133, %97
  %134 = add nsw i64 %98, -1
  %135 = icmp sgt i64 %98, 1
  br i1 %135, label %97, label %._crit_edge1366

._crit_edge1366:                                  ; preds = %._crit_edge1363, %.loopexit.._crit_edge1366_crit_edge
  %.unpack1095.unpack.unpack1392 = phi i64 [ %.unpack1095.unpack.unpack1398, %.loopexit.._crit_edge1366_crit_edge ], [ %.unpack1095.unpack.unpack1391, %._crit_edge1363 ]
  %.pre-phi1388 = phi i64 [ %.pre1387, %.loopexit.._crit_edge1366_crit_edge ], [ %94, %._crit_edge1363 ]
  %136 = sub i64 %.pre-phi1388, %.unpack1095.unpack.unpack1392
  %137 = getelementptr i32, ptr %87, i64 %136
  %138 = load i32, ptr %137, align 4, !tbaa !3
  %.not1100 = icmp eq i32 %138, 0
  br i1 %.not1100, label %142, label %139

139:                                              ; preds = %._crit_edge1366
  %140 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.284129, i64 3, ptr null, i32 -1, ptr nonnull @_QQcl.c693633e7ad6bb456b53701034d4050b, i32 41)
  %141 = call i1 @_FortranAioOutputAscii(ptr %140, ptr nonnull @_QQcl.696E66, i64 3)
  br label %146

142:                                              ; preds = %._crit_edge1366
  %143 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.c693633e7ad6bb456b53701034d4050b, i32 43)
  %144 = sub i128 0, %84
  %145 = call i1 @_FortranAioOutputInteger128(ptr %143, i128 %144)
  br label %146

146:                                              ; preds = %139, %142
  %.sink = phi ptr [ %140, %139 ], [ %143, %142 ]
  %147 = call i32 @_FortranAioEndIoStatement(ptr %.sink)
  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 {} @_FortranAReportFatalUserError(ptr, ptr, i32) local_unnamed_addr

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

declare i1 @_FortranAioOutputAscii(ptr, ptr, i64) local_unnamed_addr

declare i1 @_FortranAioOutputInteger128(ptr, i128) local_unnamed_addr

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

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

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

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) }
attributes #2 = { 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}
