Under construction

Still being built. Things may change

Warm Up

Time limit4sMemory limit512 MB

Summary
Given n dishes with warm-up and eating times, find the minimum total time to warm up and eat all of them while following the microwave readiness rules.
Level

Medium5 of 10

Topics
Brute force, Simulation
Solved
No attempts yet

Problem

Sasha has nn convenience food dishes. He has to warm them up in the microwave before eating. Each dish takes wiw_i seconds to be warmed up and cic_i seconds to be consumed. Each dish has a readiness rir_i, which starts at ri=0r_i = 0.

After the ii-th dish is placed in the microwave, its rir_i increases by 1 every second until the dish is pulled out. The microwave can contain at most one dish at any moment. rir_i must never exceed wiw_i under any circumstances. Every kk-th second, all dishes that are not being eaten and are not in the microwave have their rir_i decreased by exactly 1, unless ri=0r_i = 0, in which case it stays the same. Sasha may start eating a dish only if ri=wir_i = w_i, and he will not eat any other dish until he finishes the one he started.

Sasha can operate the microwave and eat at the same time. Placing a dish in or pulling it out takes a negligibly small amount of time. He may do these actions only at integer moments of time. Find the minimum total time Sasha needs to finish eating all dishes.

Input

The first line contains two integers nn and kk (1≤n≤101 \le n \le 10, 1≤k≤1031 \le k \le 10^3).

Each of the next nn lines contains two integers wiw_i and cic_i (1≤wi,ci≤1031 \le w_i, c_i \le 10^3).

Output

Print a single integer, the minimum amount of time Sasha needs to finish eating all dishes.

Examples1

  1. Example 1

    Input
    3 3
    5 3
    6 3
    1 2
    
    Expected output
    15