qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n, m, x = map(int, input().split())

posibilities = []

for _ in range(n):
    book = list(map(int, input().split()))
    b = posibilities[:]
    for i in b:
        posibilities.append([z+y for z, y in zip(i, book)])
    posibilities.append(book)

posibilities.sort(key=lambda i: i[0])

left = -1
right = len(posibilities)-1

while right-left > 1:
    mid = (left+right)//2
    for i in posibilities[mid][1:]:
        if i < x:
            left = mid
            break
    else:
        right = mid

for i in posibilities[right]:
    if i < x:
        print(-1)
        break
else:
    print(posibilities[right][0])


Fixed code:
n, m, x = map(int, input().split())

posibilities = []

for _ in range(n):
    book = list(map(int, input().split()))
    b = posibilities[:]
    for i in b:
        posibilities.append([z+y for z, y in zip(i, book)])
    posibilities.append(book)

posibilities.sort(key=lambda i: i[0])

for i in posibilities:
    for j in i[1:]:
        if j < x:
            break
    else:
        print(i[0])
        break
else:
    print(-1)

#left = -1
#right = len(posibilities)-1
#
#while right-left > 1:
#    mid = (left+right)//2
#    for i in posibilities[mid][1:]:
#        if i < x:
#            left = mid
#            break
#    else:
#        right = mid
#
#for i in posibilities[right]:
#    if i < x:
#        print(-1)
#        break
#else:
#    print(posibilities[right][0])
Buggy code:
N,M,X=list(map(int,input().split()))
lines = []

for i in range(N):
	lines.append(list(map(int,input().split())))
pricemin = 1500000
for i in range(2**N):
	price = 0
	count = 0
	A = [0]*M
	for j in range(N):
		if ((i >> j) & 1):
			for k in range(M):
				A[k] += lines[j][k+1]
			price += lines[j][0]
	for j in range(M):
		if A[j] >= X:
			count += 1
	if count == M and pricemin > price:
		pricemin = price
if pricemin == 1000000:
	print('-1')
else:
	print(pricemin)
			
	



Fixed code:
N,M,X=list(map(int,input().split()))
lines = []

for i in range(N):
	lines.append(list(map(int,input().split())))
pricemin = 1500000
for i in range(2**N):
	price = 0
	count = 0
	A = [0]*M
	for j in range(N):
		if ((i >> j) & 1):
			for k in range(M):
				A[k] += lines[j][k+1]
			price += lines[j][0]
	for j in range(M):
		if A[j] >= X:
			count += 1
	if count == M and pricemin > price:
		pricemin = price
if pricemin == 1500000:
	print('-1')
else:
	print(pricemin)
Buggy code:
nmx = input('')
n = int(nmx.split(' ')[0])
m = int(nmx.split(' ')[1])
x = int(nmx.split(' ')[2])

clist=[]
alist=[]
for i in range(n):
    ca = input('')
    c = ca.split(' ')[0]
    clist.append(c)
    a = []
    for j in range(1,m+1):
        a.append(ca.split(' ')[j])
    alist.append(a)

min_price=99999999999
for i in range(2**n):
    skilllist=[0]*m
    buylist = [0]*n
    cost=0
    for j in range(n):
        if (i>>j )&1:
            buylist[j]=1
            cost+=int(clist[j])
            a = alist[j]
            for k in range(m):
                skilllist[k]+=int(a[k])

    ok = True
    for skill in skilllist:
        if skill < x:
            ok = False
    if ok and cost < min_price:
        min_price=cost
    print('{}:\\{} :{} ->{} [{}]'.format(i,cost,buylist,skilllist,min_price))
if min_price == 99999999999:
    min_price=-1
print(min_price)



Fixed code:
nmx = input('')
n = int(nmx.split(' ')[0])
m = int(nmx.split(' ')[1])
x = int(nmx.split(' ')[2])

clist=[]
alist=[]
for i in range(n):
    ca = input('')
    c = ca.split(' ')[0]
    clist.append(c)
    a = []
    for j in range(1,m+1):
        a.append(ca.split(' ')[j])
    alist.append(a)

min_price=99999999999
for i in range(2**n):
    skilllist=[0]*m
    buylist = [0]*n
    cost=0
    for j in range(n):
        if (i>>j )&1:
            buylist[j]=1
            cost+=int(clist[j])
            a = alist[j]
            for k in range(m):
                skilllist[k]+=int(a[k])

    ok = True
    for skill in skilllist:
        if skill < x:
            ok = False
    if ok and cost < min_price:
        min_price=cost
#    print('{}:\\{} :{} ->{} [{}]'.format(i,cost,buylist,skilllist,min_price))
if min_price == 99999999999:
    min_price=-1
print(min_price)
Buggy code:

n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

ans = -1
for i in range(2**n):
    li = [0]*(m+1)
    print('＝＝＝＝＝＝＝＝＝＝')
    for j in range(n):
        print('i = ', i)
        print('j = ', j)
        print('(i >> j) = ', (i >> j))
        print('((i >> j) & 1) = ', ((i >> j) & 1))
        if ((i >> j) & 1):
            for k in range(m+1):
                li[k] += ca[j][k]
        print('li = ', li)
    for j in range(1, m+1):
        if li[j] < x:
            break
    else:
        if ans == -1:
            ans = li[0]
        else:
            if ans > li[0]:
                ans = li[0]
print(ans)


Fixed code:

n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

ans = -1
for i in range(2**n):
    li = [0]*(m+1)
    # print('＝＝＝＝＝＝＝＝＝＝')
    for j in range(n):
        # print('i = ', i)
        # print('j = ', j)
        # print('(i >> j) = ', (i >> j))
        # print('((i >> j) & 1) = ', ((i >> j) & 1))
        if ((i >> j) & 1):
            for k in range(m+1):
                li[k] += ca[j][k]
        # print('li = ', li)
    for j in range(1, m+1):
        if li[j] < x:
            break
    else:
        if ans == -1:
            ans = li[0]
        else:
            if ans > li[0]:
                ans = li[0]
print(ans)
Buggy code:
n, m, x = map(int, input().split())
bk = [list(map(int, input().split())) for _ in range(n)]
pr = 10 ** 7
for i in range(2 ** n):
    ef = [0] * (m + 1)
    for j in range(n):
        if i >> j & 1:
            ef = [p + q for (p, q) in zip(ef, bk[j])]
    for k in range(1, m + 1):
        if ef[k] < x:
            break
        if k == m:
            pr = min(pr, ef[0])
print(pr if pr != 10 ** 6 else -1)

Fixed code:
n, m, x = map(int, input().split())
bk = [list(map(int, input().split())) for _ in range(n)]
pr = 10 ** 7
for i in range(2 ** n):
    ef = [0] * (m + 1)
    for j in range(n):
        if i >> j & 1:
            ef = [p + q for (p, q) in zip(ef, bk[j])]
    for k in range(1, m + 1):
        if ef[k] < x:
            break
        if k == m:
            pr = min(pr, ef[0])
print(pr if pr != 10 ** 7 else -1)
Buggy code:
N, M, X = input().split()
C, A = [], []
for _ in range(N):
    tmp = [int(a) for a in input().split()]
    C.append(tmp[0])
    A.append(tmp[1:])

mi = 1 << 100
for binary in range(1 << N):
    B = [0] * M
    c = 0
    for i in range(N):
        if binary >> N & 1:
            c += C[i]
            for j in range(M):
                B[j] += A[i][j]
    if min(B) >= X:
        mi = min(c, mi)
print(mi if mi < 1 << 99 else -1)


Fixed code:
N, M, X = map(int, input().split())
C, A = [], []
for _ in range(N):
    tmp = [int(a) for a in input().split()]
    C.append(tmp[0])
    A.append(tmp[1:])

mi = 1 << 100
for binary in range(1 << N):
    B = [0] * M
    c = 0
    for i in range(N):
        if binary >> i & 1:
            c += C[i]
            for j in range(M):
                B[j] += A[i][j]
    if min(B) >= X:
        mi = min(c, mi)
print(mi if mi < 1 << 99 else -1)
Buggy code:
n, m, x = map(int, input().split())
c = []
a = [[] for _ in range(n)]
for i in range(n):
  inp = list(map(int, input().split()))
  c.append(inp[0])
  for j in range(m):
    a[i].append(inp[j+1])
print(c)
print(a)
kumi=1
for i in range(n):
  kumi *= 2
print(kumi)
  
min_score = 10000000000000
for i in range(1, kumi):
  t = [0 for _ in range(m)]
  p = 0
  ni = format(i, 'b').zfill(n)
  for j in range(n):
    if(ni[j]=="1"):
      for kk in range(m):
        t[kk] += a[j][kk]
      p += c[j]
  flag = True
  #print(t)
  for j in range(m):
    if(t[j] < x):
      flag = False
  if(flag):
    if(min_score > p):
      min_score = p
      
if(min_score == 10000000000000):
  print(-1)
else:
  print(min_score)
      

Fixed code:
n, m, x = map(int, input().split())
c = []
a = [[] for _ in range(n)]
for i in range(n):
  inp = list(map(int, input().split()))
  c.append(inp[0])
  for j in range(m):
    a[i].append(inp[j+1])
kumi=1
for i in range(n):
  kumi *= 2
  
min_score = 10000000000000
for i in range(1, kumi):
  t = [0 for _ in range(m)]
  p = 0
  ni = format(i, 'b').zfill(n)
  for j in range(n):
    if(ni[j]=="1"):
      for kk in range(m):
        t[kk] += a[j][kk]
      p += c[j]
  flag = True
  for j in range(m):
    if(t[j] < x):
      flag = False
  if(flag):
    if(min_score > p):
      min_score = p
      
if(min_score == 10000000000000):
  print(-1)
else:
  print(min_score)
Buggy code:
n,m,x =map(int,input().split())

a = []
c = []
for _ in range(n):
    a.append(list(map(int,input().split())))
    c.append(a[-1].pop(0))

#print(a,c)

ans = 10 ** 8

for i in range(1 << n):
    cost = 0
    check = True
    d = [0 for i in range(n)]
    for j in range(n):
        if i >> j & 1:
            cost += c[j]
            for i2 in range(n):
                d[i2] += a[j][i2]
            #print(i >> j,d)
    for k in range(n):
        if d[k] < x:
            check = False
    if check:
        ans = min(ans, cost)
    #print(d,cost,check)
    
if ans == 10 ** 8:
    print(-1)
else:
    print(ans)

Fixed code:
n,m,x =map(int,input().split())

a = []
c = []
for _ in range(n):
    a.append(list(map(int,input().split())))
    c.append(a[-1].pop(0))

#print(a,c)

ans = 10 ** 8

for i in range(1 << n):
    cost = 0
    check = True
    d = [0 for i in range(m)]
    for j in range(n):
        if i >> j & 1:
            cost += c[j]
            for i2 in range(m):
                d[i2] += a[j][i2]
            #print(i >> j,d)
    for k in range(m):
        if d[k] < x:
            check = False
    if check:
        ans = min(ans, cost)
    #print(d,cost,check)
    
if ans == 10 ** 8:
    print(-1)
else:
    print(ans)
Buggy code:
import numpy as np
from itertools import combinations_with_replacement

N,M,X = map(int,input().split())
CA = []
for i in range(N):
  CA.append(list(map(int,input().split())))

OK = True
CA = np.array(CA)
sums = np.sum(CA,axis=0)
for i in range(1,M+1):
  if sums[i] < X:
    OK = False
    break

if OK == False:
  print(-1)
else:
  # As = []
  # for A in combinations_with_replacement(range(0, N), r=M):
  #   As.append(tuple(set(A)))
  # As = list(map(list, set(As)))
  min_ = sums[0]
  hoge = []
  kouho = list(range(1,N+1))
  for i in itertools.combinations_with_replacement(kouho, N):
    hoge.append(list(set(i)))
  hoge = list(map(list, set(map(tuple, hoge))))
  for i in hoge:
    mini_CA = []
    for j in i:
      mini_CA.append(CA[j])
    mini_CA = np.array(mini_CA)
    OK2 = True
    sums = np.sum(mini_CA,axis=0)
    for k in range(1,M+1):
      if sums[k] < X:
        OK2 = False
        break
    if OK2 == True and sums[0] < min_:
      min_ = sums[0]
  print(min_)

Fixed code:
import numpy as np
from itertools import combinations_with_replacement

N,M,X = map(int,input().split())
CA = []
for i in range(N):
  CA.append(list(map(int,input().split())))

OK = True
CA = np.array(CA)
sums = np.sum(CA,axis=0)
for i in range(1,M+1):
  if sums[i] < X:
    OK = False
    break

if OK == False:
  print(-1)
else:
  # As = []
  # for A in combinations_with_replacement(range(0, N), r=M):
  #   As.append(tuple(set(A)))
  # As = list(map(list, set(As)))
  min_ = sums[0]
  hoge = []
  kouho = list(range(1,N+1))
  for i in combinations_with_replacement(kouho, N):
    hoge.append(list(set(i)))
  hoge = list(map(list, set(map(tuple, hoge))))
  for i in hoge:
    mini_CA = []
    for j in i:
      mini_CA.append(CA[j-1])
    mini_CA = np.array(mini_CA)
    OK2 = True
    sums = np.sum(mini_CA,axis=0)
    for k in range(1,M+1):
      if sums[k] < X:
        OK2 = False
        break
    if OK2 == True and sums[0] < min_:
      min_ = sums[0]
  print(min_)
Buggy code:
from itertools import product
n, m, x = map(int, input().split())
costs = []
gets = []
for i in range(n):
    cost, *argo = map(int, input().split())
    costs.append(cost)
    gets.append(argo)

    
bits_list = list(product([0,1], repeat=n))
min_cost = float('inf')
cnt = 0
for bits in bits_list:
    tmp_cost = 0
    tmp_argo = [0] * m
    for i, v in enumerate(bits):
        if v:
            tmp_cost += costs[i]
            for j, p in enumerate(gets[i]):
                tmp_argo[j] += p
                
    if all(map(lambda X:X>x, tmp_argo)):
        min_cost = min(min_cost, tmp_cost)
        cnt = 1
if cnt:
    print(min_cost)
else:
    print(-1)

Fixed code:
from itertools import product
n, m, x = map(int, input().split())
costs = []
gets = []
for i in range(n):
    cost, *argo = map(int, input().split())
    costs.append(cost)
    gets.append(argo)

    
bits_list = list(product([0,1], repeat=n))
min_cost = float('inf')
cnt = 0
for bits in bits_list:
    tmp_cost = 0
    tmp_argo = [0] * m
    for i, v in enumerate(bits):
        if v:
            tmp_cost += costs[i]
            for j, p in enumerate(gets[i]):
                tmp_argo[j] += p
                
    if all(map(lambda X:X>=x, tmp_argo)):
        min_cost = min(min_cost, tmp_cost)
        cnt = 1
if cnt:
    print(min_cost)
else:
    print(-1)
Buggy code:
from sys import stdin
import itertools

n, m, x = [int(x) for x in stdin.readline().rstrip().split()]
c = [[int(y) for y in x.rstrip().split()] for x in stdin.readlines()]
c.sort()
mi = -1
r = 0

for j in range(1, m + 1):
    li = [x[j] for x in c]
    li.sort(reverse=True)
    for i in range(len(li)):
        if sum(li[:i]) >= x:
            r = max(r, i)
            break

for h in range(r,n):
    for i in itertools.combinations(c, h):
        cnt = [0] * m
        mon = 0
        for j in i:
            cnt = [cnt[k]+j[k+1] for k in range(len(cnt))]
            mon += j[0]
            print(cnt)            
            if sum(1 for k in cnt if k >= x) == m:
                if mi > mon or mi == -1:

                    mi = mon
                break

print(mi)


Fixed code:
from sys import stdin
import itertools

n, m, x = [int(x) for x in stdin.readline().rstrip().split()]
c = [[int(y) for y in x.rstrip().split()] for x in stdin.readlines()]
c.sort()
mi = -1
r = 0

for j in range(1, m + 1):
    li = [x[j] for x in c]
    li.sort(reverse=True)
    for i in range(1, len(li) + 1):
        if sum(li[:i]) >= x:
            r = max(r, i)
            break

for h in range(r, n + 1):
    for i in itertools.combinations(c, h):
        cnt = [0] * m
        mon = 0
        for j in i:
            cnt = [cnt[k]+j[k+1] for k in range(len(cnt))]
            mon += j[0]
            if sum(1 for k in cnt if k >= x) == m:
                if mi > mon or mi == -1:

                    mi = mon
                break

print(mi)
Buggy code:
n,m,x = map(int,input().split())
li1 = []
li2 = []
for i in range(n):
    li1.append(list(map(int,input().split())))
for i in range(2**n):
    b = '0'*(n-len(bin(i))+2)+bin(i)[2:]
    total = 0
    li3 = [0]*m
    f = 1
    for j in range(n):
        if b[j] == "1":
            total += li1[j][0]
            for k in range(m):
                li3[k] += li1[j][k+1]
    for j in range(m):
        if li3[j] < x:
            f = 0
    if f == 1:
        li2.append(total)
print(min(li2))


Fixed code:
n,m,x = map(int,input().split())
li1 = []
li2 = []
for i in range(n):
    li1.append(list(map(int,input().split())))
for i in range(2**n):
    b = '0'*(n-len(bin(i))+2)+bin(i)[2:]
    total = 0
    li3 = [0]*m
    f = 1
    for j in range(n):
        if b[j] == "1":
            total += li1[j][0]
            for k in range(m):
                li3[k] += li1[j][k+1]
    for j in range(m):
        if li3[j] < x:
            f = 0
    if f == 1:
        li2.append(total)
if len(li2) >= 1:
    print(min(li2))
else:
    print(-1)
Buggy code:
import itertools
import copy
n,m,x = map(int,input().split())
ans = [0 for i in range(m)]
books = []
answer = 1000000000000000000000
for i in range(n):
    books.append(list(map(int,input().split())))
for i in range(n):
    stock = list(list(itertools.combinations([num for num in range(n)], i+1)))
    for j in stock:
        cost = 0
        ans = [0 for i in range(m)]
        for k in j:
            for e,l in enumerate(books[k]):
                if e == 0:
                    cost += l
                else:
                    ans[e-1] += l
            if min(ans) >= x and cost < answer:
                answer = copy.deepcopy(cost)
if answer = 1000000000000000000000:
    print(-1)
else:
    print(answer)


Fixed code:
import itertools
import copy
n,m,x = map(int,input().split())
ans = [0 for i in range(m)]
books = []
answer = 1000000000000000000000
for i in range(n):
    books.append(list(map(int,input().split())))
for i in range(n):
    stock = list(list(itertools.combinations([num for num in range(n)], i+1)))
    for j in stock:
        cost = 0
        ans = [0 for i in range(m)]
        for k in j:
            for e,l in enumerate(books[k]):
                if e == 0:
                    cost += l
                else:
                    ans[e-1] += l
            if min(ans) >= x and cost < answer:
                answer = copy.deepcopy(cost)
if answer == 1000000000000000000000:
    print(-1)
else:
    print(answer)
Buggy code:
n, m, x = map(int, input().split()) 
c_l = []
a_l = []

for _ in range(n):
    a_list = list(map(int, input().split())) 
    c_l.append(a_list[0])
    a_l.append(a_list[1:])

min_c = 9999999999
for i in range(2 ** n):
    bag_c = []
    bag_a = []
    for j in range(n):
        if ((i >> j) & 1):  
            bag_c.append(c_l[j])  
            bag_a.append(a_l[j])
        l = len(bag_a)
        c_sum = 0
        s_sum = [0]*m
        for ii in range(l):
            c_sum += bag_c[ii]
            for mm in range(m):
                s_sum[mm] += bag_a[ii][mm]
        if min(s_sum) >= x and c_sum < min_c:
            min_c = c_sum
print(min_c)

Fixed code:
INF = 99999999999

n, m, x = map(int, input().split()) 
c_l = []
a_l = []

for _ in range(n):
    a_list = list(map(int, input().split())) 
    c_l.append(a_list[0])
    a_l.append(a_list[1:])

min_c = INF
for i in range(2 ** n):
    bag_c = []
    bag_a = []
    for j in range(n):
        if ((i >> j) & 1):  
            bag_c.append(c_l[j])  
            bag_a.append(a_l[j])
        l = len(bag_a)
        c_sum = 0
        s_sum = [0]*m
        for ii in range(l):
            c_sum += bag_c[ii]
            for mm in range(m):
                s_sum[mm] += bag_a[ii][mm]
        if min(s_sum) >= x and c_sum < min_c:
            min_c = c_sum
if min_c == INF:
    print(-1)
else:   
    print(min_c)
Buggy code:
import itertools
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m, x = map(int, readline().split())
c = [list(map(int, readline().split())) for _ in range(n)]

ans = 10 ** 9 + 7
for l in list(itertools.product([0, 1], repeat=n)):
    cart = [0] * (m + 1)
    for i, a in enumerate(l):
        if a == 1:
        array = c[i]
        cart = list(map(lambda x,y: x+y, cart, array))
    if min(cart[1::]) >= x:
        ans = min(ans, cart[0])
print(ans if ans != 10 ** 9 + 7 else '-1')

Fixed code:
import itertools
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m, x = map(int, readline().split())
c = [list(map(int, readline().split())) for _ in range(n)]

ans = 10 ** 9 + 7
for l in list(itertools.product([0, 1], repeat=n)):
    cart = [0] * (m + 1)
    for i in [i for i, a in enumerate(l) if a == 1]:
        array = c[i]
        cart = list(map(lambda x,y: x+y, cart, array))
    if min(cart[1::]) >= x:
        ans = min(ans, cart[0])
        
print(ans if ans != 10 ** 9 + 7 else '-1')
Buggy code:
def cos_per_find(count, cost, skills):
    if count == N:
        if min(skills) >= X:
            return cost
        else:
            return INF
    improved_skills = [a+b for a, b in zip(skills, contents[count])]
    return min(cos_per_find(count+1, cost, skills), cos_per_find(count+1, cost+price[count], improved_skills))

INF = float(inf)
N, M, X = map(int, input().split())
price = []
contents = []
for i in range(N):
    C, *A = map(int, input().split())
    price.append(C)
    contents.append(A)
if ans(:=cos_per_find(0, 0, [0]*M))== INF:
    print(-1)
else:
    print(ans)

Fixed code:
def cos_per_find(count, cost, skills):
    if count == N:
        if min(skills) >= X:
            return cost
        else:
            return INF
    improved_skills = [a+b for a, b in zip(skills, contents[count])]
    return min(cos_per_find(count+1, cost, skills), cos_per_find(count+1, cost+price[count], improved_skills))

INF = float('inf')
N, M, X = map(int, input().split())
price = []
contents = []
for i in range(N):
    C, *A = map(int, input().split())
    price.append(C)
    contents.append(A)
if (ans := cos_per_find(0, 0, [0]*M)) == INF:
    print(-1)
else:
    print(ans)
Buggy code:
n,m,x=map(int,input().split())
cam = [list(map(int, input().split())) for i in range(n)]
ans=10000*12

for i in range(2**n):
    a=[0]*m
    cst=0
    for j in range(n):
        bag=[]
        if (i>>j)&1:
            cst+=cam[j][0]
            for k in range(1,m+1):
                a[k-1]+=cam[j][k]
    if all(elem >= x for elem in a):
        ans=min(ans,cst)
    
if ans<100000*12:
    print(ans)
else:
    print(-1)






        





        

    

Fixed code:
n,m,x=map(int,input().split())
cam = [list(map(int, input().split())) for i in range(n)]
ans=10000**12

for i in range(2**n):
    a=[0]*m
    cst=0
    for j in range(n):
        bag=[]
        if (i>>j)&1:
            cst+=cam[j][0]
            for k in range(1,m+1):
                a[k-1]+=cam[j][k]
    if all(elem >= x for elem in a):
        ans=min(ans,cst)
    
if ans<10000**12:
    print(ans)
else:
    print(-1)
Buggy code:
import numpy as np

N,M,X = map(int,input().split())
arr = [np.array(list(map(int,input().split()))) for _ in range(N)]
ans = float('inf')
for i in range(2**N):
  arr_sum = np.array([0]*(M+1))
  for j in range(N):
    if i>>j&1:
      arr_sum += arr[j]
  if np.all(arr_sum[1:]>=X):
    ans = min(ans,arr_sum[0])
print(ans)

Fixed code:
import numpy as np

N,M,X = map(int,input().split())
arr = [np.array(list(map(int,input().split()))) for _ in range(N)]
ans = float('inf')
for i in range(2**N):
  arr_sum = np.array([0]*(M+1))
  for j in range(N):
    if i>>j&1:
      arr_sum += arr[j]
  if np.all(arr_sum[1:]>=X):
    ans = min(ans,arr_sum[0])

if ans == float('inf'):
  print(-1)
else:
  print(ans)