1348_E. Phoenix and Berries
Phoenix is picking berries in his backyard. There are n shrubs, and each shrub has a_i red berries and b_i blue berries.

Each basket can contain k berries. But, Phoenix has decided that each basket may only contain berries from the same shrub or berries of the same color (red or blue). In other words, all berries in a basket must be from the same shrub or/and have the same color.

For example, if there are two shrubs with 5 red and 2 blue berries in the first shrub and 2 red and 1 blue berries in the second shrub then Phoenix can fill 2 baskets of capacity 4 completely: 

  * the first basket will contain 3 red and 1 blue berries from the first shrub; 
  * the second basket will contain the 2 remaining red berries from the first shrub and 2 red berries from the second shrub. 



Help Phoenix determine the maximum number of baskets he can fill completely!

Input

The first line contains two integers n and k ( 1≤ n, k ≤ 500) — the number of shrubs and the basket capacity, respectively.

The i-th of the next n lines contain two integers a_i and b_i (0 ≤ a_i, b_i ≤ 10^9) — the number of red and blue berries in the i-th shrub, respectively.

Output

Output one integer — the maximum number of baskets that Phoenix can fill completely.

Examples

Input


2 4
5 2
2 1


Output


2


Input


1 5
2 3


Output


1


Input


2 5
2 1
1 3


Output


0


Input


1 2
1000000000 1


Output


500000000

Note

The first example is described above.

In the second example, Phoenix can fill one basket fully using all the berries from the first (and only) shrub.

In the third example, Phoenix cannot fill any basket completely because there are less than 5 berries in each shrub, less than 5 total red berries, and less than 5 total blue berries.

In the fourth example, Phoenix can put all the red berries into baskets, leaving an extra blue berry behind.
```python
n,k=map(int,input().split())
totA=0
totB=0
A=[0]
B=[0]

dp=[]
for i in range(n+1):
    h=[]
    for j in range(k):
        h.append(False)
    dp.append(h)
dp[0][0]=True


for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
    totA+=a
    totB+=b
    
for i in range(1,n+1):
    for j in range(k):
        dp[i][j]=dp[i-1][(j-(A[i]%k)+k)%k]
        for l in range(0,min(k-1,A[i])):
            if((A[i]-l)%k + B[i]>=k):
                dp[i][j]|=dp[i-1][(j-l)%k]


ans=0
for i in range(k):
    if(dp[n][i]):
        ans=max(ans,(totA+totB-i)//k)
print(ans)



```