program main
  implicit none
  integer :: n, k, m, p, i, j, j2, j3, a, b, c(1000)
  integer, allocatable :: dp(:)
  read *, n, m
  k = 2 ** n
  allocate (dp(0:k - 1))
  dp = 10 ** 9
  dp(0) = 0

  do i = 1, m
    read *, a, b
    read *, c(1:b)
    j3 = 0
    do p = 1, b
      j3 = ibset(j3, c(p) - 1)
    end do
    do j = k - 1, 0, -1  ! 配る
      j2 = ior(j, j3)
      dp(j2) = min(dp(j2), dp(j) + a)
    end do
  end do
  if (dp(k - 1) == 10 ** 9) dp(k - 1) = -1
  print "(i0)", dp(k - 1)
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"

@_QFEc = internal global [1000 x i32] undef
@_QFEdp.0 = internal unnamed_addr global ptr null
@_QFEdp.7 = internal unnamed_addr global i64 1
@_QQcl.b3cc1bb3f401de4bd7788307f9eff96e = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3203/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.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 { 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 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.b3cc1bb3f401de4bd7788307f9eff96e, i32 5)
  %7 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %5, i32 4)
  %8 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %4, i32 4)
  %9 = call i32 @_FortranAioEndIoStatement(ptr %6)
  %10 = load i32, ptr %5, align 4, !tbaa !3
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %__mlir_math_ipowi_i32.exit, label %12

12:                                               ; preds = %0
  %13 = icmp slt i32 %10, 1
  br i1 %13, label %__mlir_math_ipowi_i32.exit, label %.preheader.i

.preheader.i:                                     ; preds = %12
  %14 = and i32 %10, 1
  %.not3.i = icmp eq i32 %14, 0
  %15 = select i1 %.not3.i, i32 1, i32 2
  %16 = icmp eq i32 %10, 1
  br i1 %16, label %__mlir_math_ipowi_i32.exit, label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.preheader.i, %.lr.ph.i
  %spec.select4.i = phi i32 [ %spec.select.i, %.lr.ph.i ], [ %15, %.preheader.i ]
  %17 = phi i32 [ %19, %.lr.ph.i ], [ %10, %.preheader.i ]
  %18 = phi i32 [ %20, %.lr.ph.i ], [ 2, %.preheader.i ]
  %19 = lshr i32 %17, 1
  %20 = mul i32 %18, %18
  %21 = and i32 %17, 2
  %.not.i = icmp eq i32 %21, 0
  %22 = select i1 %.not.i, i32 1, i32 %20
  %spec.select.i = mul i32 %22, %spec.select4.i
  %23 = icmp ult i32 %17, 4
  br i1 %23, label %__mlir_math_ipowi_i32.exit, label %.lr.ph.i

__mlir_math_ipowi_i32.exit:                       ; preds = %.lr.ph.i, %12, %0, %.preheader.i
  %common.ret.op.i = phi i32 [ 1, %0 ], [ %15, %.preheader.i ], [ 0, %12 ], [ %spec.select.i, %.lr.ph.i ]
  %24 = add i32 %common.ret.op.i, -1
  %25 = sext i32 %24 to i64
  %26 = call i64 @llvm.smax.i64(i64 %25, i64 -1)
  %27 = add nsw i64 %26, 1
  %28 = shl nuw nsw i64 %27, 2
  %29 = call ptr @malloc(i64 %28)
  %30 = icmp eq i64 %27, 0
  %31 = zext i1 %30 to i64
  store ptr %29, ptr @_QFEdp.0, align 8, !tbaa !7
  store i64 %31, ptr @_QFEdp.7, align 8, !tbaa !7
  %.not = icmp eq ptr %29, null
  br i1 %.not, label %45, label %.preheader

.preheader:                                       ; preds = %__mlir_math_ipowi_i32.exit
  %32 = icmp sgt i32 %24, -1
  br i1 %32, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader
  %33 = add i64 %26, 2
  %34 = icmp ne i64 %27, 0
  %umin.neg = sext i1 %34 to i64
  %35 = add i64 %33, %umin.neg
  %min.iters.check = icmp ult i64 %35, 8
  br i1 %min.iters.check, label %.lr.ph.preheader353, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %35, -8
  %ind.end = sub i64 %27, %n.vec
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %36 = getelementptr i32, ptr %29, i64 %index
  store <4 x i32> <i32 1000000000, i32 1000000000, i32 1000000000, i32 1000000000>, ptr %36, align 4, !tbaa !3
  %37 = getelementptr i32, ptr %36, i64 4
  store <4 x i32> <i32 1000000000, i32 1000000000, i32 1000000000, i32 1000000000>, ptr %37, align 4, !tbaa !3
  %index.next = add nuw i64 %index, 8
  %38 = icmp eq i64 %index.next, %n.vec
  br i1 %38, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %35, %n.vec
  br i1 %cmp.n, label %.loopexit, label %.lr.ph.preheader353

.lr.ph.preheader353:                              ; preds = %.lr.ph.preheader, %middle.block
  %.ph = phi i64 [ %27, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.ph354 = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader353, %.lr.ph
  %39 = phi i64 [ %43, %.lr.ph ], [ %.ph, %.lr.ph.preheader353 ]
  %40 = phi i64 [ %41, %.lr.ph ], [ %.ph354, %.lr.ph.preheader353 ]
  %41 = add nuw nsw i64 %40, 1
  %42 = getelementptr i32, ptr %29, i64 %40
  store i32 1000000000, ptr %42, align 4, !tbaa !3
  %43 = add nsw i64 %39, -1
  %44 = icmp ugt i64 %39, 1
  br i1 %44, label %.lr.ph, label %.loopexit, !llvm.loop !12

45:                                               ; preds = %__mlir_math_ipowi_i32.exit
  %46 = call {} @_FortranAReportFatalUserError(ptr nonnull @_QQcl.16373402fa3425c6e46827601abb88fa, ptr nonnull @_QQcl.b3cc1bb3f401de4bd7788307f9eff96e, i32 8)
  %.unpack308.unpack.unpack = load i64, ptr @_QFEdp.7, align 8, !tbaa !7
  %47 = select i1 %30, i64 1, i64 %.unpack308.unpack.unpack
  store ptr null, ptr @_QFEdp.0, align 8, !tbaa !7
  store i64 %47, ptr @_QFEdp.7, align 8, !tbaa !7
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %middle.block, %.preheader, %45
  %.unpack260.unpack.unpack = phi i64 [ %31, %.preheader ], [ %47, %45 ], [ %31, %middle.block ], [ %31, %.lr.ph ]
  %48 = sub i64 0, %.unpack260.unpack.unpack
  %49 = getelementptr i32, ptr %29, i64 %48
  store i32 0, ptr %49, align 4, !tbaa !3
  %50 = load i32, ptr %4, align 4, !tbaa !3
  %51 = icmp sgt i32 %50, 0
  br i1 %51, label %.lr.ph328, label %._crit_edge329

.lr.ph328:                                        ; preds = %.loopexit
  %52 = zext i32 %50 to i64
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  %.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
  %.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
  %.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
  %.neg = add nsw i64 %25, 1
  %53 = icmp sgt i32 %24, -1
  br label %54

54:                                               ; preds = %.lr.ph328, %._crit_edge326
  %55 = phi i64 [ %52, %.lr.ph328 ], [ %103, %._crit_edge326 ]
  %56 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.b3cc1bb3f401de4bd7788307f9eff96e, i32 12)
  %57 = call i1 @_FortranAioInputInteger(ptr %56, ptr nonnull %2, i32 4)
  %58 = call i1 @_FortranAioInputInteger(ptr %56, ptr nonnull %3, i32 4)
  %59 = call i32 @_FortranAioEndIoStatement(ptr %56)
  %60 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.b3cc1bb3f401de4bd7788307f9eff96e, i32 13)
  %61 = load i32, ptr %3, align 4, !tbaa !3
  %62 = call i32 @llvm.smax.i32(i32 %61, i32 0)
  %63 = zext i32 %62 to i64
  store ptr @_QFEc, ptr %1, align 8, !tbaa !7
  store i64 4, ptr %.fca.1.gep, align 8, !tbaa !7
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  store i8 9, ptr %.fca.4.gep, align 1, !tbaa !7
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  store i64 %63, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  store i64 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %64 = call i1 @_FortranAioInputDescriptor(ptr %60, ptr nonnull %1)
  %65 = call i32 @_FortranAioEndIoStatement(ptr %60)
  %66 = load i32, ptr %3, align 4, !tbaa !3
  %67 = icmp sgt i32 %66, 0
  br i1 %67, label %.lr.ph323.preheader, label %._crit_edge

.lr.ph323.preheader:                              ; preds = %54
  %68 = zext i32 %66 to i64
  %min.iters.check338 = icmp ult i32 %66, 8
  br i1 %min.iters.check338, label %.lr.ph323.preheader350, label %vector.ph339

vector.ph339:                                     ; preds = %.lr.ph323.preheader
  %n.vec341 = and i64 %68, 4294967288
  %ind.end342 = or i64 %n.vec341, 1
  br label %vector.body345

vector.body345:                                   ; preds = %vector.body345, %vector.ph339
  %index346 = phi i64 [ 0, %vector.ph339 ], [ %index.next349, %vector.body345 ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph339 ], [ %75, %vector.body345 ]
  %vec.phi347 = phi <4 x i32> [ zeroinitializer, %vector.ph339 ], [ %76, %vector.body345 ]
  %69 = getelementptr [1000 x i32], ptr @_QFEc, i64 0, i64 %index346
  %wide.load = load <4 x i32>, ptr %69, align 16, !tbaa !3
  %70 = getelementptr i32, ptr %69, i64 4
  %wide.load348 = load <4 x i32>, ptr %70, align 16, !tbaa !3
  %71 = add <4 x i32> %wide.load, <i32 -1, i32 -1, i32 -1, i32 -1>
  %72 = add <4 x i32> %wide.load348, <i32 -1, i32 -1, i32 -1, i32 -1>
  %73 = shl nuw <4 x i32> <i32 1, i32 1, i32 1, i32 1>, %71
  %74 = shl nuw <4 x i32> <i32 1, i32 1, i32 1, i32 1>, %72
  %75 = or <4 x i32> %73, %vec.phi
  %76 = or <4 x i32> %74, %vec.phi347
  %index.next349 = add nuw i64 %index346, 8
  %77 = icmp eq i64 %index.next349, %n.vec341
  br i1 %77, label %middle.block336, label %vector.body345, !llvm.loop !13

middle.block336:                                  ; preds = %vector.body345
  %bin.rdx = or <4 x i32> %76, %75
  %78 = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %bin.rdx)
  %cmp.n344 = icmp eq i64 %n.vec341, %68
  br i1 %cmp.n344, label %._crit_edge, label %.lr.ph323.preheader350

.lr.ph323.preheader350:                           ; preds = %.lr.ph323.preheader, %middle.block336
  %indvars.iv.ph = phi i64 [ 1, %.lr.ph323.preheader ], [ %ind.end342, %middle.block336 ]
  %.0322.ph = phi i32 [ 0, %.lr.ph323.preheader ], [ %78, %middle.block336 ]
  br label %.lr.ph323

.lr.ph323:                                        ; preds = %.lr.ph323.preheader350, %.lr.ph323
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph323 ], [ %indvars.iv.ph, %.lr.ph323.preheader350 ]
  %.0322 = phi i32 [ %84, %.lr.ph323 ], [ %.0322.ph, %.lr.ph323.preheader350 ]
  %79 = add nsw i64 %indvars.iv, -1
  %80 = getelementptr [1000 x i32], ptr @_QFEc, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !3
  %82 = add i32 %81, -1
  %83 = shl nuw i32 1, %82
  %84 = or i32 %83, %.0322
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %68
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph323, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph323, %middle.block336, %54
  %.0.lcssa = phi i32 [ 0, %54 ], [ %78, %middle.block336 ], [ %84, %.lr.ph323 ]
  br i1 %53, label %.lr.ph325, label %._crit_edge326

.lr.ph325:                                        ; preds = %._crit_edge
  %.unpack289 = load ptr, ptr @_QFEdp.0, align 8, !tbaa !7
  %.unpack296.unpack.unpack = load i64, ptr @_QFEdp.7, align 8, !tbaa !7
  br label %85

85:                                               ; preds = %.lr.ph325, %85
  %86 = phi i64 [ %.neg, %.lr.ph325 ], [ %101, %85 ]
  %87 = phi i32 [ %24, %.lr.ph325 ], [ %100, %85 ]
  %88 = or i32 %87, %.0.lcssa
  %89 = sext i32 %88 to i64
  %90 = sub i64 %89, %.unpack296.unpack.unpack
  %91 = getelementptr i32, ptr %.unpack289, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !3
  %93 = sext i32 %87 to i64
  %94 = sub i64 %93, %.unpack296.unpack.unpack
  %95 = getelementptr i32, ptr %.unpack289, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !3
  %97 = load i32, ptr %2, align 4, !tbaa !3
  %98 = add i32 %97, %96
  %99 = call i32 @llvm.smin.i32(i32 %92, i32 %98)
  store i32 %99, ptr %91, align 4, !tbaa !3
  %100 = add i32 %87, -1
  %101 = add nsw i64 %86, -1
  %102 = icmp sgt i64 %86, 1
  br i1 %102, label %85, label %._crit_edge326

._crit_edge326:                                   ; preds = %85, %._crit_edge
  %103 = add nsw i64 %55, -1
  %104 = icmp sgt i64 %55, 1
  br i1 %104, label %54, label %._crit_edge329.loopexit

._crit_edge329.loopexit:                          ; preds = %._crit_edge326
  %.unpack265.pre = load ptr, ptr @_QFEdp.0, align 8, !tbaa !7
  %.unpack272.unpack.unpack.pre = load i64, ptr @_QFEdp.7, align 8, !tbaa !7
  br label %._crit_edge329

._crit_edge329:                                   ; preds = %._crit_edge329.loopexit, %.loopexit
  %.unpack272.unpack.unpack = phi i64 [ %.unpack272.unpack.unpack.pre, %._crit_edge329.loopexit ], [ %.unpack260.unpack.unpack, %.loopexit ]
  %.unpack265 = phi ptr [ %.unpack265.pre, %._crit_edge329.loopexit ], [ %29, %.loopexit ]
  %105 = sub i64 %25, %.unpack272.unpack.unpack
  %106 = getelementptr i32, ptr %.unpack265, i64 %105
  %107 = load i32, ptr %106, align 4, !tbaa !3
  %108 = icmp eq i32 %107, 1000000000
  br i1 %108, label %109, label %110

109:                                              ; preds = %._crit_edge329
  store i32 -1, ptr %106, align 4, !tbaa !3
  br label %110

110:                                              ; preds = %109, %._crit_edge329
  %111 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.b3cc1bb3f401de4bd7788307f9eff96e, i32 24)
  %.unpack277 = load ptr, ptr @_QFEdp.0, align 8, !tbaa !7
  %.unpack284.unpack.unpack = load i64, ptr @_QFEdp.7, align 8, !tbaa !7
  %112 = sub i64 %25, %.unpack284.unpack.unpack
  %113 = getelementptr i32, ptr %.unpack277, i64 %112
  %114 = load i32, ptr %113, align 4, !tbaa !3
  %115 = call i1 @_FortranAioOutputInteger32(ptr %111, i32 %114)
  %116 = call i32 @_FortranAioEndIoStatement(ptr %111)
  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 i1 @_FortranAioInputDescriptor(ptr, 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 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 nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i32 @llvm.vector.reduce.or.v4i32(<4 x i32>) #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 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}
!13 = distinct !{!13, !10, !11}
!14 = distinct !{!14, !11, !10}
