전에 안올린 숙제
''' Q 1282 제곱수 만들기 34: n i: 1 > 1 2 > 4 3 > 9 4 > 16 5 > 25 <<<<<< 이걸 써야됨 6 > 36 34보다 큼 '''
# a = int(input())
# if a == 2: # print(1, 1)
# else: # for i in range(a):
# if i * i >= a:
# print(a - (i-1)*(i-1), i-1)
# break
#
''' i = range (n) 할때는 순서 (1번2번3번) range (n, m) 할때는 n, n+1, n+2, n+3 --- m-1 '''
# a, b = input().split()
# a = int(a)
# b = int(b)
# s = 0 # if a % 2 == 0:
# print('-', a, sep='', end='')
# elif a % 2 == 1:
# print(a, sep='', end='')
# for i in range (a+1, b+1):
# if i % 2 == 0:
# s -= i
# print('-', i, sep='', end='')
# elif i % 2 == 1:
# s += i # print ('+', i, sep='', end='')
# if a % 2 == 0: # print('=', s-a, sep='')
# if a % 2 == 1:
# print('=', s+a, sep='')
#
'''ONEWAY Q1278'''
# n = int(input())
# a = n // 10 # if a < 1:
# print('1')
# elif 10 > a >= 1:
# print('2')
# elif 100 > a >= 10:
# print('3')
# elif 1000 > a >= 100:
# print('4')
# elif 10000 > a >= 1000:
# print('5')
# elif 100000 > a >= 10000:
# print('6')
# elif 1000000 > a >= 100000:
# print('7')
# elif 10000000 > a >= 1000000:
# print('8')
# elif 100000000 > a >= 10000000:
# print('9')
# elif 1000000000 > a >= 100000000:
# print('10')
# '''ANOTHERWAY Q1278'''
# n = int(input())
# s = 0
# for i in range(100):
# n //= 10 # n = n // 10
# 12345 -> 1234
# s += 1
# s = s + 1 counting how many times
# if n == 0:
# break
# print(s)
#
# ''' Q 1675 a = 'A' b = ord(a) b += 1 a = chr(b) print(a) >>> 'B' '''
# words = input()
# for i in range(len(words)):
# if words[i] == ' ':
# print(' ',end='')
# elif words[i] == 'a':
# print('x', end='')
# elif words[i] == 'b':
# print('y', end='')
# elif words[i] == 'c':
# print('z', end='')
# else:
# b = ord(words[i])
# c = b - 3
# d = chr(c)
# print(d, end='')
# '''Q 1277'''
# a = int(input())
# numbers = list(input().split())
# '''list()안넣어도 돼는데 보기편함'''
# print(numbers[0], numbers[a//2], numbers[a-1])
# '''0부터가 첫번째!!'''
N, K = input().split()
N = int(N)
K = int(K)
time = 0
money = 0
for i in range(N):
Wt, Wm, Bt, Bm = input().split()
Wt = int(Wt)
Wm = int(Wm)
Bt = int(Bt)
Bm = int(Bm)
if (time + Wt <= K) and (time + Bt <= K):
if Wt/Wm > Bt/Bm:
time += Wt
money += Wm
elif Wt/Wm <= Bt/Bm:
time += Bt
money += Bm
elif (time + Wt > K) and (time + Bt <= K):
time += Bt
money += Bm
print(money)
'''
test if works:
4 3000
1000 2000 300 700
1100 1900 400 900
900 1800 400 700
1200 2300 500 1200
'''