Valera loves his garden, where n fruit trees grow.

This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat).

Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?


-----Input-----

The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day. 

Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 ≤ a_{i}, b_{i} ≤ 3000) — the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.


-----Output-----

Print a single integer — the maximum number of fruit that Valera can collect. 


-----Examples-----
Input
2 3
1 5
2 3

Output
8

Input
5 10
3 20
2 20
1 20
4 20
5 20

Output
60



-----Note-----

In the first sample, in order to obtain the optimal answer, you should act as follows.   On the first day collect 3 fruits from the 1-st tree.  On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree.  On the third day collect the remaining fruits from the 2-nd tree.  

In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.

Difficulty: interview

Starter code:

Solutions:
"""
Codeforces Round 252 Div 2 Problem B

Author  : chaotic_iak
Language: Python 3.3.4
"""

def read(mode=2):
    # 0: String
    # 1: List of strings
    # 2: List of integers
    inputs = input().strip()
    if mode == 0:
        return inputs
    if mode == 1:
        return inputs.split()
    if mode == 2:
        return [int(x) for x in inputs.split()]

def write(s="\n"):
    if isinstance(s, list): s = " ".join(s)
    s = str(s)
    print(s, end="")

################################################### SOLUTION
n,v = read()
a = []
for i in range(n):
    a.append(read())
a.sort(key=lambda x: x[0])
res = 0
for day in range(1, 3002):
    n = 0
    while a and a[0][0] <= day:
        if a[0][1] <= v-n:
            n += a[0][1]
            a[0][1] = 0
        else:
            a[0][1] -= v-n
            n = v
        if a[0][1] == 0:
            a.pop(0)
        else:
            break
    while a and a[0][0] == day-1: a.pop(0)
    res += n
print(res)

n, v = [int(i) for i in input().split()]
a = [0] * n
b = [0] * n
days1 = [0] * 3001
days2 = [0] * 3001
for i in range(n):
    a[i], b[i] = [int(j) for j in input().split()]
    days1[a[i] - 1] += b[i]
    days2[a[i]] += b[i]
res = 0
for i in range(3001):
    left = max(0, v - days2[i])
    res += max(0, min(v, days2[i]))
    res += min(left, days1[i])
    if i != 3000:
        days2[i + 1] -= min(left, days1[i])
print(res)

n, v = map(int, input().split())
T = 3010
a = [[] for i in range(T)]
for i in range(n):
    x, y = map(int, input().split())
    a[x].append([y, 1])

    
ans = 0
for i in range(T):
    a[i] = a[i][::-1]
    j = 0
    cur = v
    while j < len(a[i]):
        if a[i][j][0] > cur:
            ans += cur
            if a[i][j][1] == 0:
                j += 1                
            else:
                a[i][j][0] -= cur
            break
        else:
            ans += a[i][j][0]
            cur -= a[i][j][0]
        j += 1
    for t in range(j, len(a[i])):
        if a[i][t][1] != 0:
            a[i + 1].append([a[i][t][0], 0])    
            
    
print(ans)

n, v = [int(c) for c in input().split()]
m = [[0, 0] for i in range(3003)]



for i in range(n):
    a, b = [int(c) for c in input().split()]
    m[a][1] += b
    m[a+1][0] += b


res = 0

for i in range(1,3002):
    if v <= m[i][0]:
        res += v
    else:
        from_future = v - m[i][0]
        got_fr = min(from_future, m[i][1])
        res += m[i][0] + got_fr
        m[i+1][0] -= got_fr

print(res)

n, v = list(map(int, input().split()))

g = [0 for x in range(3002)]

for i in range(n):
    a, b = list(map(int, input().split()))
    g[a]+=(b)

r = 0

for i in range(1, 3002):
    c = v
    r += min(c, max(g[i-1], 0))
    c -= max(g[i-1], 0)
    if c > 0:
        r += min(c, g[i])
        g[i] = max(g[i]-c, 0)


print(r)


n,v=map(int,input().split())
w=[]
q=[v for i in range(3003)]
for i in range(n):
    w.append(list(map(int,input().split())))
w=sorted(w,reverse=True)
s=0
for i in w:
    a=i[0]
    b=i[1]
    if q[a+1]>=b:
        q[a+1]-=b
        s+=b
        b=0
    else:
        b-=q[a+1]
        s+=q[a+1]
        q[a+1]=0
    if q[a]>=b:
        q[a]-=b
        s+=b
        b=0
    else:
        b-=q[a]
        s+=q[a] 
        q[a]=0
print(s)

n, v = list(map(int, input().split()))
trees = {}
days = set()
for i in range(n):
        a, b = list(map(int, input().split()))
        if a not in trees:
            trees[a] = b
        else:
            trees[a] += b
        days.add(a)

max_days = max(days)
total = 0
for a in range(1, max_days+1):
#    print(a)
#    print(trees)
    prev_collected = 0
    if a-1 in trees:
        prev_collected = min(trees[a-1], v)
        trees[a-1] -= prev_collected
        total += prev_collected
#        print('prev_collected', prev_collected)
    if a in trees:
        collected = min(trees[a], v-prev_collected)
        trees[a] -= collected
        total += collected
#        print('collected', collected)
    elif a-1 in trees and prev_collected == 0:
        add_collected = min(trees[a-1], v)
        trees[a-1] -= add_collected
        total += add_collected
#        print('add_collected', add_collected)

if max_days in trees:
    total += min(trees[max_days], v)
print(total)
        


n, v = map(int, input().split())
trees = [list(map(int, input().split())) for i in range(n)]
trees.sort()

mergedTrees = []
treeIndex = 0
currentDay = trees[treeIndex][0]
while treeIndex < len(trees):
	nbFruits = 0
	while treeIndex < len(trees) and trees[treeIndex][0] == currentDay:
		nbFruits += trees[treeIndex][1]
		treeIndex += 1
	mergedTrees.append([currentDay, nbFruits])
	if treeIndex < len(trees):
		currentDay = trees[treeIndex][0]

collected = 0
for treeIndex, tree in enumerate(mergedTrees):
	used = 0
	if treeIndex >= 1:
		lastTree = mergedTrees[treeIndex - 1]
		if lastTree[0] == tree[0] - 1:
			used = min(v, lastTree[1])

		collected += min(v, lastTree[1])


	nextUsed = min(tree[1], v - used)
	collected += nextUsed
	tree[1] -= nextUsed

if len(mergedTrees) > 0:
	lastTree = mergedTrees[len(mergedTrees) - 1]
	collected += min(v, lastTree[1])

print(collected)

n,v = [int(i) for i in input().split()]
f = 0
l = [0]*3002
for i in range(n):
    a,b = [int(i) for i in input().split()]
    l[a] += b

for i in range(1,3002):
    pick = min(v,l[i-1])
    l[i-1] -= pick
    pick2 = min(v-pick,l[i])
    l[i] -= pick2
    f += pick + pick2

print(f)


n, v = list(map(int,input().split()))
f = list()
for i in range(n):
    f.append(list(map(int,input().split())))
f.sort()
sum = 0
today = 0
tomor = 0
day = 0
rest = 0
for tree in f:
    if tree[0] > day + 1:
        sum += min(tomor, v)
        tomor = tree[1]
        sum += min(tomor, v)
        rest = v - min(tomor, v)
        tomor -= min(tomor,v)
        day = tree[0]
    elif tree[0] == day + 1:
        sum += min(tomor, v)
        rest = v - min(tomor, v)
        tomor = tree[1]
        t = min(tomor, rest)
        sum += t
        rest -= t
        tomor -= t
        day = tree[0]
    else :
        tomor += tree[1]
        t = min(tomor, rest)
        sum += t
        rest -= t
        tomor -= t
sum += min(tomor, v)
print(sum)


def a():	
	n, v = list(map(int, input().split(" ")))
	d = []
	for i in range(n):
		d.append(list(map(int, input().split(" "))))
	d.sort()

	cur = 0
	nex = 0
	k = 0
	r = 0
	for i in range(d[-1][0] + 2):
		nex = 0
		p = v
		if k != n:
			while(d[k][0] < i):
				k += 1
				if k == n:
					break
		if k != n:
			while(d[k][0] == i):
				nex += d[k][1]
				k += 1
				if k == n:
					break
		r += min(p, cur)
		p -= min(p, cur)
		r += min(p, nex)
		cur = nex - min(p, nex)
	return r

print(a())



total_plucked = 0
n,v = list(map(int,input().split()))
fruits = [0] * 3002
plucked = [0] * 30002
for _ in range(n):
    a,b = list(map(int,input().split()))
    fruits[a] = fruits[a] + b
for i in range(1,3002):
   plucked[i] = fruits[i - 1] if (fruits[i - 1] <= v) else v
   if(plucked[i] < v):
       pluck = fruits[i] if (fruits[i] <= v - plucked[i]) else v - plucked[i]
       plucked[i] += pluck
       fruits[i] -= pluck
   #print(fruits[i - 1],plucked[i])
   total_plucked += plucked[i]
print(total_plucked)
 



n, v = map(int, input().split(' '))
trees = dict()
count = 0
b_last = 0

for i in range(n):
  a, b = map(int, input().split(' '))
  if trees.get(a):
    trees[a] += b
  else:
    trees[a] = b
    
m = max(trees.keys())    
for i in range(1, m+2):
  if trees.get(i):
    k = min(v, b_last)
    count += k
    k1 = min(v - k, trees[i])
    count += k1
    b_last = trees[i] - k1
  else:
    count += min(v, b_last)  
    b_last = 0
  
print(count)

n, v = list(map(int, input().split()))

g = [0 for x in range(3002)]

for i in range(n):
    a, b = list(map(int, input().split()))
    g[a]+=(b)

r = 0

for i in range(1, 3002):
    c = v
    r += min(c, max(g[i-1], 0))
    c -= max(g[i-1], 0)
    if c > 0:
        r += min(c, g[i])
        g[i] = max(g[i]-c, 0)


print(r)
	    


n, v = map(int, input().split())
s, t = 0, [0] * 3002
for i in range(n):
    a, b = map(int, input().split())
    t[a] += b
for d in range(1, 3002):
    ds = min(t[d - 1], v)
    s += ds
    ds = min(t[d], v - ds)
    t[d] -= ds
    s += ds
print(s)

# -*- coding: utf-8 -*-
import sys
f = sys.stdin
#f = open('H:\\Portable Python 3.2.5.1\\test_248B1.txt') 
n, v  = list(map(int, f.readline().strip().split()))

p = [0]*3002
for i in range(n):
    a, b  = list(map(int, f.readline().strip().split()))
    p[a] += b
#print(p[:5])    
S = 0
for k in range(1,len(p)):
    dv = min(v,p[k-1])
    S += dv
    p[k-1] -= dv    

    dv = min(v-dv,p[k])    
    S += dv
    p[k] -= dv      
    #print(k, S, v, dv, p[:5])   
print(S)



R = lambda:list(map(int, input().split()))
n, v = R()
M = 3001
x = [0] * M
for i in range(n):
  a, b = R()
  x[a - 1] += b
y = [0] * M
s = 0
for i in range(M):
  a = min(v, y[i])
  b = min(v - a, x[i])
  s += a + b
  if i < M - 1:
    y[i + 1] = x[i] - b
print(s)

R = lambda:list(map(int, input().split()))
n, v = R()
M = 3005
x = [0] * M
for i in range(n):
    a, b = R()
    x[a - 1] += b
y = [0] * M
s = 0
for i in range(M):
    a = min(v, y[i])
    b = min(v - a, x[i])
    s += a + b
    if i < M - 1:
        y[i + 1] = x[i] - b
print(s)

DEBUG = False
n, v = [int(x) for x in input().split()]
fruits = []
for i in range(n):
	aa, bb = [int(x) for x in input().split()]
	fruits.append([aa, bb])

fruits.sort()

day, t_harvested, tot, curr = 0, 0, 0, []

def remove_old():
	while fruits != [] and fruits[0][0] < day-1:
		t = fruits.pop(0)
		if DEBUG: print("Rotten {} on day {}".format(t, day))
	while curr != [] and curr[0][0] < day-1:
		curr.pop(0)
		#print("Rotten/harvested {} on day {}".format(t, day))

def add_current():
	for f in fruits:
		if day-1 <= f[0] <= day:
			curr.append(f)
			if DEBUG: print("New fruit {} on day {}".format(f, day))

def harvest_todays():
	nonlocal t_harvested
	nonlocal tot

	while curr != []:
		t = curr.pop(0)
		harvest = min(t[1], v-t_harvested)
		if DEBUG: print("Harvested {} of {} on day {}".format(harvest, t, day))
		t_harvested += harvest
		t[1] -= harvest
		tot += harvest
		#if harvest == 0: ## BUG!!!
		#	break


while fruits != []:

	remove_old()

	add_current()

	harvest_todays()
	day += 1
	t_harvested = 0

print(tot)




def main() :

    R = lambda : map(int, input().split())
    n, v = R()
    mlist = [0] * 3003
    for i in range(n) :
        a, b = R()
        mlist[a] += b
    mlist2 = mlist[:]
    ans = 0
    for i in range(1, 3002) :
        tmp = min(v, mlist[i])
        ans += tmp
        mlist[i + 1] += min(mlist[i] - tmp, mlist2[i])
    print(ans)

def __starting_point():
    main()
__starting_point()

n, v = map(int, input().split())
d, s = {}, 0
for i in range(n):
    a, b = map(int, input().split())
    d[a] = d.get(a, 0) + b
    s += b

r = v
for i in sorted(d.keys()):
    d[i] -= min(d[i], r)
    r, b = v, min(d[i], v)
    d[i] -= b
    if i+1 in d:
        r -= b

print(s - sum(d.values()))

[n, v] = input().split()
v1 = []
for i in range(3002):
    v1.append(0)
v = int(v)
maxx = 0
for i in range(int(n)):
    [a, b] = input().split()
    v1[int(a)] += int(b)
    maxx = max(int(a), maxx)
res = 0
for i in range(1, maxx+2):
    delt = min(v, v1[i] + v1[i-1])
    res += delt
    d = v1[i-1] - delt
    v1[i] += min(d, 0)
print(res)

import sys
import math
  
n, v = [int(x) for x in (sys.stdin.readline()).split()]
k = [0] * 3002

for i in range(n):
    a, b = [int(x) for x in (sys.stdin.readline()).split()]
    k[a] += b
    
i = 1
res = 0
while(i <= 3001):
    val = 0
    if(k[i - 1] < v):
        val = k[i - 1]
        res += val 
        d = v - val
        if(k[i] < d):
            res += k[i]
            k[i] = 0
        else:
            res += d
            k[i] = k[i] - d
    else:
        res += v
     
    i += 1    
print(res)  

n, v = [int(x) for x in input().split()]
l = [0] * 3002
for i in range(n):
	a, b = [int(x) for x in input().split()]
	l[a] += b
ans = 0
for i in range(1, 3002):
	left = v
	if l[i - 1]:
		ans += min(left, l[i - 1])
		left -= min(left, l[i - 1])
	ans += min(left, l[i])
	l[i] -= min(left, l[i])
print(ans)


def main():
    n, v = map(int, input().split())
    l = [0] * 3002
    for _ in range(n):
        a, b = map(int, input().split())
        l[a] += b
    a = res = 0
    for b in l:
        x = a + b
        if x < v:
            res += x
            a = 0
        else:
            res += v
            if a < v:
                a = x - v
            else:
                a = b
    print(res)


def __starting_point():
    main()
__starting_point()