The Infosci Pirate Crew

Given N islands with coordinates, treasure values, and safe hardness, choose a monotone northeast path and a hardness interval to maximize collected value minus interval length.

Hard8Dynamic programmingSortingTwo pointersSegment treeNo attempts yetTime limit1sMemory limit512 MB

Problem

The Infosci Pirate Crew has shown up. The crew is made up of students from the Information Science Project course, and it is known for showing no mercy. Hardly anyone knows who the captain is, and only the nickname 'King God' gets passed around. The crew has already swept up treasure across the world, and the West Sea is the last place left.

Donggeon, the captain's right hand, is ordered to bring back the treasure hidden on the NN islands of the West Sea. He starts at (00, 00), and the crew's hideout sits at (10910^9, 10910^9). A hard southwest wind is blowing, so Donggeon cannot move in any direction that decreases his xx coordinate or his yy coordinate. Once he has stopped at an island, the only islands he can stop at afterwards are the ones whose xx coordinate and yy coordinate are both at least as large.

Each island holds one safe with treasure inside. The safe on island ii has treasure worth viv_i and hardness hih_i. A safe opens with a custom cracking tool. A safe that is too hard wrecks the tool, and a safe that is too soft shatters the treasure with it, so the tool has to be set in advance. Donggeon can set the tool exactly once, as he leaves (00, 00). Setting it to open every safe with hardness between aa and bb inclusive costs bab - a won. He may stop at an island and pass it by without opening its safe.

Donggeon assumed the crew would cover the setup cost, but the captain is just as harsh with his own men.

'Um, captain, the cost of setting the tool, you are covering that, right...'

'Nope. Use your own money. Oh, and if you do not bring back MM won worth of treasure, you are fired.'

Find the smallest amount of his own money Donggeon has to spend to keep his place in the crew.

Input

The first line contains the number of islands in the West Sea, NN (1N20001 \le N \le 2\,000), and the smallest treasure value Donggeon has to collect, MM (1M10121 \le M \le 10^{12}).

Each of the next NN lines contains four integers xix_i, yiy_i, viv_i, hih_i separated by spaces, giving the xx coordinate of the island, its yy coordinate, the value of its treasure, and the hardness of its safe. All four values are between 11 and 10910^9 inclusive.

Output

Print on one line the smallest amount of his own money Donggeon has to spend. If he cannot collect treasure worth MM or more no matter what he does, print -1.