Small PhD Restaurant

Given N challenges with cost A_i and payoff B_i, starting money M, choose an order to maximize final money while affording each cost.

Medium6GreedySortingDynamic programmingNo attempts yetTime limit2sMemory limit512 MB

Problem

"There is probably a place where all waiters have a PhD in, I don't know, some stuff." Dudu, 2014

Dudu is hungry, so he sat down in a Thai restaurant. Only after taking his seat did he realize where he was: the PhD restaurant, where every staff member holds a doctorate in some stuff.

Each staff member also prepared one challenge from his or her own field, and Dudu attempts those challenges while he waits for his food. Attempting the challenge of staff member ii costs AiA_i, and completing it pays BiB_i.

Each challenge can be completed at most once, and they can be attempted in any order. Dudu is smart enough to complete any challenge, but he must be able to pay AiA_i before he attempts challenge ii. Dudu starts with MM money. Find the largest amount he can end up with.

Input

The first line contains two integers NN and MM, the number of challenges and the money Dudu starts with.

The second line contains NN integers A1,A2,,ANA_1, A_2, \dots, A_N, where AiA_i is the cost of attempting challenge ii.

The third line contains NN integers B1,B2,,BNB_1, B_2, \dots, B_N, where BiB_i is the payoff for completing challenge ii.

  • 1N10001 \le N \le 1000
  • 0M,Ai,Bi1060 \le M, A_i, B_i \le 10^6

Output

Print one integer, the maximum amount of money Dudu can obtain.

Hint

In the first example Dudu starts with 100 and can proceed in this order.

  • Pay 80, get 90 back. Dudu now has 110.
  • Pay 50, get 70 back. Dudu now has 130.
  • Pay 110, get 150 back. Dudu now has 170.