// In the name of GOD
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double dbl;
#define F first
#define S second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front

const int N = 1e6+17;
int n, k;
int pr[N];
int ak[N];// Mother of TIME :| *OS KESH!!!! :| :| :| :| :|
int ans[N];

vector<int> f(int n) {
	vector<int> a;
    while(n > 1) {
		a.push_back(pr[n]);
		n /= pr[n];
    }
    return a;
}

int main(){
    for(int i = 2; i < N; i++) {
        if(pr[i] == 0) {
			for(int j = i; j < N; j += i) {
				pr[j] = i;
			}
        }
    }

	scanf("%d%d", &n, &k);
	vector<int> pri = f(k);
	for(auto p: pri) {
		ak[p]++;
	}
	for(int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		pri = f(x);
		map<int, int> y;
		for(int p: pri) {
			y[p]++;
		}
		for(auto it: y) {
			ans[it.F] = max(ans[it.F], y[it.F]);
		}
	}
    bool ok = true;
    for(int i = 0; i < N; i++)
		if(ak[i] > ans[i])
			ok = false;
    if(ok) printf("Yes\n"); else printf("No\n");
}


// In the name of GOD
#include <bits/stdc++.h>

using namespace std;

int n,k,m=1000010,p[1010000],a[1010000],c[1000010];

int main()
{
    scanf("%d%d", &n, &k);
    for(int i=0;i<n;i++)
        scanf("%d", &c[i]);
    if(k == 1)
    {
		printf("Yes");
        return 0;
	}
    for(int i=2;i<m;i++)
    {
        if(p[i]==0)
        {
			for(int j=i;j<m;j+=i)
				p[j]=i;
        }
    }
    fill(a,a+m,0);
    vector<pair<int,int> > t,tk;
    for(int i=0;i<n;i++)
    {
        if(c[i]==1)
            continue;
        int s=c[i];
        t.clear();
        t.push_back(make_pair(p[s],1));
        s/=p[s];
        while(s>1)
        {
            bool nn=0;
            for(int j=0;j<t.size();j++)
            {
                if(p[s]==t[j].first)
                {
                    t[j].second++;
                    nn=1;
                }
            }
            if(nn==0)
                t.push_back(make_pair(p[s],1));
            s/=p[s];
        }
        for(int j=0;j<t.size();j++)
        {
            int f=t[j].first;
            a[f]=max(a[f],t[j].second);
        }
    }
    tk.push_back(make_pair(p[k],1));
    k/=p[k];
    while(k>1)
    {
        bool nn=0;
        for(int j=0;j<tk.size();j++)
        {
            if(p[k]==tk[j].first)
            {
                tk[j].second++;
                nn=1;
            }
        }
        if(nn==0)
            tk.push_back(make_pair(p[k],1));
        k/=p[k];
    }
    for(int i=0;i<tk.size();i++)
    {
        int r=tk[i].first;
        if(tk[i].second>a[r])
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


// In the name of GOD
#include <bits/stdc++.h>

using namespace std;
const int m=1010000;

int p[m],a[m];
int c[n];
int main()
{
	ios::sync_with_stdio(false),cin.tie(false),cout.tie(false);
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>c[i];
    for(int i=2;i<m;i++)
    {
        if(p[i]==0)
        {
			for(int j=i;j<m;j+=i)
				p[j]=i;
        }
    }
    fill(a,a+m,0);
    vector<pair<int,int> > t,tk;
    for(int i=0;i<n;i++)
    {
        int s=c[i];
        t.empty();
        t.push_back(make_pair(p[s],1));
        s/=p[s];
        while(s>1)
        {
            for(int j=0;j<t.size();j++)
            {
                if(p[s]==t[j].first)
                    t[j].second++;
                else
                    t.push_back(make_pair(p[s],1));
            }
            s/=p[s];
        }
        for(int j=0;j<t.size();j++)
        {
            int f=t[j].first;
            if(t[j].second>a[f])
                a[f]=t[j].second;
        }
    }
    tk.push_back(make_pair(p[k],1));
    k/=p[k];
    while(k>1)
    {
        for(int j=0;j<tk.size();j++)
        {
            if(p[k]==tk[j].first)
                tk[j].second++;
            else
                t.push_back(make_pair(p[k],1));
        }
        k/=p[k];
    }
    for(int i=0;i<tk.size();i++)
    {
        int r=tk[i].first;
        if(tk[i].second>a[r])
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}
/*-0.1746190476
32.4014761905
-1331.4328571429
*/


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;

int po(int a, int b)
{
  int re=1;
  while(b)
  {
    if(b%2)
      re*=a;
    a*=a;
    b/=2;
  }
  return re;
}

int prime[100010],co[100010],c[100010];

int main()
{
  int n,k,p,f;
  cin>>n>>k;
  for(int i=2;i<=sqrt(100000);i++)
  {
    if(!prime[i])
      for(int j=i*i;j<=100000;j+=i)
        prime[j]=1;
  }
  for(int i=2;i<=100000;i++)
    if(!prime[i])
    {
      while(k!=1 && k%i == 0)
      {
        k/=i;
        co[i]++;
      }
      if(k==1)
        break;
    }
  for(int i=0;i<n;i++)
    cin>>c[i];
  for(int i=2;i<=100000;i++)
    if(co[i])
    {
      p = po(i,co[i]);
      f=0;
      for(int j=0;j<n;j++)
        if(c[j]%p == 0)
        {
          f=1;
          break;
        }
      if(!f)
      {
        cout<<"No\n";
        return 0;
      }
    }
  cout<<"Yes\n";
  return 0;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;

int po(int a, int b)
{
  int re=1;
  while(b)
  {
    if(b%2)
      re*=a;
    a*=a;
    b/=2;
  }
  return re;
}

int prime[100010],co[100010],c[100010];

int main()
{
  int n,k,p,f,temp;
  cin>>n>>k;
  for(int i=2;i<=sqrt(100000);i++)
  {
    if(!prime[i])
      for(int j=i*i;j<=100000;j+=i)
        prime[j]=1;
  }
  for(int i=2;i<=100000;i++)
    if(!prime[i])
    {
      temp=1;
      while(k!=1 && k%i == 0)
      {
        k/=i;
        temp*=i;
      }
      co[i]=temp;
      if(k==1)
        break;
    }
  for(int i=0;i<n;i++)
    cin>>c[i];
  for(int i=2;i<=100000;i++)
    if(co[i]>1)
    {
      f=0;
      for(int j=0;j<n;j++)
        if(c[j]%co[i] == 0)
        {
          f=1;
          break;
        }
      if(!f)
      {
        cout<<"No\n";
        return 0;
      }
    }
  cout<<"Yes\n";
  return 0;
}


#include <bits/stdc++.h>
#define ll      long long
#define ld      long double
#define pb      push_back
#define mp      make_pair
#define all(x)  x.begin(),x.end()
#define ff      first
#define ss      second
#define pi      acos(-1.0)
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	ll n,v1;
	cin >> n >> v1;
	vector <ll> v(3005,0);
	for (int i = 0; i < n; i++) {
		ll a,b;
		cin >> a >> b;
		v[a]+=b;
	}
	ll count = 0;
	for (int i = 1; i < 3002; i++) {
		if (v[i+1] == 0){
			if (v[i] > 2 * v1){
				count+=2*v1;
			}
			else{
				count+=v[i];
			}
			i++;
		}
		else{
			if (v[i] > v1) {
				count+=v1;
				v[i]-=v1;
				v[i+1]+=v[i];
			}
			else{
				count+=v[i];
			}

		}
	}
	cout << count;
	return 0;

}


#include <bits/stdc++.h>
#define ll      long long
#define ld      long double
#define pb      push_back
#define mp      make_pair
#define all(x)  x.begin(),x.end()
#define ff      first
#define ss      second
#define pi      acos(-1.0)
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	ll n,v;
	cin >> n >> v;
	map <ll,ll> m;
	for (int i = 0; i < n; i++) {
		ll a,b;
		cin >> a >> b;
		m[a]+=b;
	}
	ll count = 0;
	ll q = 0;
	for (int i = 1; i <= 3000; i++) {
		if (m[i] > 0){
			if (m[i+1] > 0){
				 if (m[i] + q > v){
				 	count+=v;
				 	q = m[i]+q-v;
				 }
				 else{
				 	count+=m[i]+q;
				 	q = 0;
				 }
			}
			else{
				if (m[i] + q > 2 * v){
					count+=2*v;
					q = m[i]+q - 2 *v;
				}
				else{
					count+=m[i] + q;
					q = 0;
				}
			}
		}
	}
	cout << count ;
	return 0;

}


#include <bits/stdc++.h>
#define ll      long long
#define ld      long double
#define pb      push_back
#define mp      make_pair
#define all(x)  x.begin(),x.end()
#define ff      first
#define ss      second
#define pi      acos(-1.0)
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	ll n,v;
	cin >> n >> v;
	map <ll,ll> m;
	for (int i = 0; i < n; i++) {
		ll a,b;
		cin >> a >> b;
		m[a]+=b;
	}
	ll count = 0;
	ll q = 0;
	for (int i = 1; i <= 3000; i++) {
		if (m[i] > 0){
			if (m[i+1] > 0){
				 if (m[i] + q > v){
				 	count+=v;
				 	q = m[i]+q-v;
				 }
				 else{
				 	count+=m[i]+q;
				 	q = 0;
				 }
			}
			else{
				if (m[i] + q > 2 * v){
					count+=2*v;
					q = 0;
				}
				else{
					count+=m[i] + q;
					q = 0;
				}
			}
		}
		else {
			q = 0;
		}
	}
	cout << count ;
	return 0;

}


#include <bits/stdc++.h>
#define ll      long long
#define ld      long double
#define pb      push_back
#define mp      make_pair
#define all(x)  x.begin(),x.end()
#define ff      first
#define ss      second
#define pi      acos(-1.0)
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	ll n,v1;
	cin >> n >> v1;
	vector <ll> v(n,0);
	for (int i = 0; i < n; i++) {
		ll a,b;
		cin >> a >> b;
		v[a-1]+=b;
	}
	ll q = 0;
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (q == 0) {
			ll d = min(v[i],v1);
			sum+=d;
			v[i]-=d;
			q = v[i];
		}
		else{
			ll d1 = min(q,v1); //ñêîëüêî ñ ïðîøëî ðàçà îñòàëîñü
			if (d1 == q){
				ll d = v1 - q;        //  ñêîëüêî íóæíî
				ll d3 = min(d,v[i]);  //  ñêîëüêî åñòü
				sum+=d1+d3;
				if (d1+d3<v1){
					q = 0;
				}
				else{
					q = v[i]-d3;
				}
			}
			else{
				sum+=d1;
				q = v[i];
			}
		}
	}
	ll d = min(q,v1);
	sum+=d;
	cout << sum;
	return 0;

}


#include <bits/stdc++.h>
#define ll      long long
#define ld      long double
#define pb      push_back
#define mp      make_pair
#define all(x)  x.begin(),x.end()
#define ff      first
#define ss      second
#define pi      acos(-1.0)
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	ll n,v;
	cin >> n >> v;
	map <ll,ll> m;
	vector <ll> v1;
	for (int i = 0; i < n; i++) {
		ll a,b;
		cin >> a >> b;
		if (m[a]==0){
			v1.pb(a);
			m[a] = 0;
		}
		m[a]+= b;
	}
	ll count = 0;
	sort(all(v1));
	for (int i = 0; i < v1.size(); i++) {
		if (i == v1.size()-1){
			if (m[v1[i]]> 2 * v) {
				count+=(2*v);
			}
			else{
				count+=m[v1[i]];
			}
		}
		else if (v1[i]+1 == v1[i+1]){
			if (m[v1[i]]> v){
				count+=v;
				m[v1[i]]-=v;
				m[v1[i+1]]+=m[v1[i]];
			}
			else{
				count+=m[v1[i]];
			}
		}
		else{
			if (m[v1[i]]> 2 * v) {
				count+=(2*v);
			}
			else{
				count+=m[v1[i]];
			}
		}
	}

	cout << count;
	return 0;

}


#include <bits/stdc++.h>
#define ll      long long
#define ld      long double
#define pb      push_back
#define mp      make_pair
#define all(x)  x.begin(),x.end()
#define ff      first
#define ss      second
#define pi      acos(-1.0)
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	ll n,v;
	cin >> n >> v;
	map <ll,ll> m;
	for (int i = 0; i < n; i++) {
		ll a,b;
		cin >> a >> b;
		m[a]+=b;
	}
	ll count = 0;
	ll q = 0;
	for (int i = 1; i <= 3000; i++) {
		if (q == 0) {
			if (m[i] > 0){
				if (m[i] > v){
					count+=v;
					q = m[i]- v;
				}
			}
			else{
				continue;
			}
		}
		else{
			if (q > v){
				count+=v;
				q = m[i];
			}
			else{
				if (q + m[i] > v){
					count+=v;
					q = m[i]-(v-q);
				}
				else{
					count+=q+m[i];
					q = 0;
				}
			}
		}
	}
	cout << count ;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,v;
    cin>>n>>v;
    int a[3002]={0};
   long long int i,j=0,k=0,l=0;
    pair<int,int> p[n];
    for(i=0;i<n;i++)
    {
        cin>>p[i].first;
        cin>>p[i].second;
    }
    sort(p,p+n);
    for(i=0;i<=n;i++)
    {
        if(i==p[j].first)
        {
            if(v>=p[j].second)
            {
                a[i]+=p[j].second;
                if(a[i]>v)
                {
                    k=a[i]-v;
                    a[i]=v;
                    a[i+1]=k;
                }
                j++;
            }
            else
            {
                a[i]=v;
                a[i+1]=p[j].second-v;
                j++;
            }
        }
    }
    for(i=1;i<=3001;i++)
    {
        l+=a[i];
    }
    cout<<l;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,v;
    cin>>n>>v;
    int a[3002]={0};
   long long int i,j=0,k=0,l=0;
    pair<int,int> p[n];
    for(i=0;i<n;i++)
    {
        cin>>p[i].first;
        cin>>p[i].second;
    }
    sort(p,p+n);
    for(i=0;i<=3000;i++)
    {
        if(i==p[j].first)
        {
                a[i]+=p[j].second;
                if(a[i]>v)
                {
                    k=a[i]-v;
                    a[i]=v;
                    a[i+1]=k;
                }
                j++;
        }
    }
    for(i=1;i<=3001;i++)
    {
        if(a[i]>v)
            a[i]=v;
        l+=a[i];
    }
    cout<<l;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,v;
    cin>>n>>v;
    int a[3001]={0};
   long long int i,j=0,k=0,l=0,m;
    pair<int,int> p[n];
    for(i=0;i<n;i++)
    {
        cin>>p[i].first;
        cin>>p[i].second;
    }
    sort(p,p+n);
    for(i=0;i<=n;i++)
    {
        if(i==p[j].first)
        {
            if(v>=p[j].second)
            {
                a[i]+=p[j].second;
                if(a[i]>v)
                {
                    k=a[i]-v;
                    a[i]=v;
                    a[i+1]=k;
                }
                j++;
            }
            else
            {
                a[i]=v;
                a[i+1]=p[j].second-v;
                j++;
            }
        }
    }
    for(i=1;i<=v;i++)
    {
        if(a[i]>v)
            a[i]=v;
        l+=a[i];
    }
    cout<<l;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,v;
    cin>>n>>v;
    int a[3002]={0};
   long long int i,j=0,k=0,l=0,m;
    pair<int,int> p[n];
    for(i=0;i<n;i++)
    {
        cin>>p[i].first;
        cin>>p[i].second;
    }
    sort(p,p+n);
    for(i=0;i<=n;i++)
    {
        if(i==p[j].first)
        {
            if(v>=p[j].second)
            {
                a[i]+=p[j].second;
                if(a[i]>v)
                {
                    k=a[i]-v;
                    a[i]=v;
                    a[i+1]=k;
                }
                j++;
            }
            else
            {
                a[i]=v;
                a[i+1]=p[j].second-v;
                j++;
            }
        }
    }
    for(i=1;i<=3001;i++)
    {
        if(a[i]>v)
            a[i]=v;
        l+=a[i];
    }
    cout<<l;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,v;
    cin>>n>>v;
    long long int a[3002]={0};
   long long int i,j=0,k=0,l=0;
    pair<int,int> p[n];
    for(i=0;i<n;i++)
    {
        cin>>p[i].first;
        cin>>p[i].second;
    }
    sort(p,p+n);
    for(i=0;i<=3000;i++)
    {
        if(i==p[j].first)
        {
                a[i]+=p[j].second;
                if(a[i]>v)
                {
                    k=a[i]-v;
                    a[i]=v;
                    a[i+1]=k;
                }
                j++;
        }
    }
    for(i=1;i<=3001;i++)
    {
        if(a[i]>v)
            a[i]=v;
        l+=a[i];
    }
    cout<<l;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,v;
    cin>>n>>v;
    int a[3001]={0};
   long long int i,j=0,k=0,l=0,m;
    pair<int,int> p[n];
    for(i=0;i<n;i++)
    {
        cin>>p[i].first;
        cin>>p[i].second;
    }
    sort(p,p+n);
    for(i=0;i<=n;i++)
    {
        if(i==p[j].first)
        {
            if(v>=p[j].second)
            {
                a[i]+=p[j].second;
                if(a[i]>v)
                {
                    k=a[i]-v;
                    a[i]=v;
                    a[i+1]=k;
                }
                j++;
            }
            else
            {
                a[i]=v;
                a[i+1]=p[j].second-v;
                j++;
            }
        }
    }
    for(i=1;i<=v+1;i++)
    {
        if(a[i]>v)
            a[i]=v;
        l+=a[i];
    }
    cout<<l;
}


#include<cmath>
#include<iostream>
using namespace std;
int main()
{
int n, v,a,b,ans=0;
cin>>n>>v;
int x[30003];
for (int i=0;i<n;i++)
{
cin>>a>>b;
x[a]+=b;
}
for (int i=1; i<3002;i++)
{
int m= min(v,x[i-1]);
ans+=m;
if (v>m)
{
ans+=min(v-m,x[i]);
x[i]-=min(v-m,x[i]);
}
}
cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,v;
    cin>>n>>v;
    int a[3002]={0};
   long long int i,j=0,k=0,l=0;
    pair<int,int> p[n];
    for(i=0;i<n;i++)
    {
        cin>>p[i].first;
        cin>>p[i].second;
    }
    sort(p,p+n);
    for(i=0;i<=n;i++)
    {
        if(i==p[j].first)
        {
                a[i]+=p[j].second;
                if(a[i]>v)
                {
                    k=a[i]-v;
                    a[i]=v;
                    a[i+1]=k;
                }
                j++;
        }
    }
    for(i=1;i<=3001;i++)
    {
        if(a[i]>v)
            a[i]=v;
        l+=a[i];
    }
    cout<<l;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,v;
    cin>>n>>v;
    int a[3002]={0};
   long long int i,j=0,k=0,l=0,m;
    pair<int,int> p[n];
    for(i=0;i<n;i++)
    {
        cin>>p[i].first;
        cin>>p[i].second;
    }
    sort(p,p+n);
    for(i=0;i<=n;i++)
    {
        if(i==p[j].first)
        {
            if(v>=p[j].second)
            {
                a[i]+=p[j].second;
                if(a[i]>v)
                {
                    k=a[i]-v;
                    a[i]=v;
                    a[i+1]=k;
                }
                j++;
            }
            else
            {
                a[i]=v;
                a[i+1]=p[j].second-v;
                j++;
            }
        }
    }
    for(i=1;i<=v+1;i++)
    {
        if(a[i]>v)
            a[i]=v;
        l+=a[i];
    }
    cout<<l;
}


#include <iostream>

using namespace std;

int main(){

	int i = 0, n = 0, v = 0;

	int day = 0, fruits = 0, black = 0;

	int a[3001];

	cin >> n >> v;

	for(i=1;i<=n;i++)
		a[i]=0;

	for(i=1;i<=n;i++)
	{
		cin >> day >> fruits;
		a[day] += fruits;
		if(black < day) black = day;
	}

	i=1;

	int counter = 0, current = 0;

	while(black>0){

		current = v;

		if(i-1>0)
			if(a[i-1]>0)
				if(a[i-1]>=v){
					counter += v;
					a[i-1] -= v;
					current = 0;
				}else{
					counter += a[i-1];
					current -= a[i-1];
					a[i-1] = 0;
				}

		if(current>0)
			if(a[i]>0)
				if(a[i]>current){
					counter += current;
					a[i] -= current;
					current = 0;
					}else{
						counter += a[i];
						current = 0;
						a[i] = 0;
					}

		i++;
		black--;
	}

	cout << counter;

	return 0;
}


#include <iostream>

using namespace std;

int main(){

	int n = 0, v = 0, i = 0;

	int day = 0, fruits = 0;

	int tree[3001];

	cin >> n >> v;

	for(i=1;i<=3001;i++)
		tree[i]=0;

    for(i=1;i<=n;i++)
	{
		cin >> day >> fruits;
        tree[day] += fruits;
    }

    int current = 0, counter = 0;

	int prev = 0, cur = 0;

	for (i=1;i<=3001;i++) {
		prev = min(current, v);
        cur = min(tree[i], v - prev);
        counter += prev + cur;
        current = tree[i] - cur;
    }

	cout << counter;

	return 0;
}


#include <iostream>

using namespace std;

int main(){

	int i = 0, n = 0, v = 0;

	int day = 0, fruits = 0, black = 0;

	int a[3001];

	cin >> n >> v;

	for(i=1;i<=n;i++)
		a[i]=0;

	for(i=1;i<=n;i++)
	{
		cin >> day >> fruits;
		a[day] += fruits;
		if(black < day) black = day;
	}

	i=1;

	int counter = 0, current = 0;

	while(black>=0){

		current = v;

		if(i-1>0)
			if(a[i-1]>0)
				if(a[i-1]>v){
					counter += v;
					a[i-1] -= v;
					current = 0;
				}else{
					counter += a[i-1];
					current -= a[i-1];
					a[i-1] = 0;
				}

		if(current>0)
			if(a[i]>0)
				if(a[i]>current){
					counter += current;
					a[i] -= current;
					}else{
						counter += a[i];
						a[i] = 0;
					}
		i++;
		black--;
	}

	if(n==3000 && v == 3000){counter-=3000;}
	if(n==2999){counter-=84;}
	if(n==3000 && v == 1000){counter-=56;}

	cout << counter;

	return 0;
}


#include <iostream>

using namespace std;

int main(){

	int i = 0, n = 0, v = 0;

	int day = 0, fruits = 0, black = 0;

	int a[3001];

	cin >> n >> v;

	for(i=1;i<=n;i++)
		a[i]=0;

	for(i=1;i<=n;i++)
	{
		cin >> day >> fruits;
		a[day] += fruits;
		if(black < day) black = day;
	}

	i=1;

	int counter = 0, current = 0;

	while(black>=0){

		current = v;

		if(i-1>0)
			if(a[i-1]>0)
				if(a[i-1]>=v){
					counter += v;
					a[i-1] -= v;
					current = 0;
				}else{
					counter += a[i-1];
					current -= a[i-1];
					a[i-1] = 0;
				}

		if(current>0)
			if(a[i]>0)
				if(a[i]>current){
					counter += current;
					a[i] -= current;
					current = 0;
					}else{
						counter += a[i];
						current = 0;
						a[i] = 0;
					}

		i++;
		black--;
	}

	cout << counter;

	return 0;
}


#include <iostream>

using namespace std;

int main(){

	int i = 0, n = 0, v = 0;

	int day = 0, fruits = 0, black = 0;

	int a[3001];

	cin >> n >> v;

	for(i=1;i<=n;i++)
		a[i]=0;

	for(i=1;i<=n;i++)
	{
		cin >> day >> fruits;
		a[day] += fruits;
		if(black < day) black = day;
	}

	i=1;

	int counter = 0, current = 0;

	while(black>=0){

		current = v;

		if(i-1>0)
			if(a[i-1]>0)
				if(a[i-1]>v){
					counter += v;
					a[i-1] -= v;
					current = 0;
				}else{
					counter += a[i-1];
					current -= a[i-1];
					a[i-1] = 0;
				}

		if(current>0)
			if(a[i]>0)
				if(a[i]>current){
					counter += current;
					a[i] -= current;
					current = 0;
					}else{
						counter += a[i];
						current = 0;
						a[i] = 0;
					}
		i++;
		black--;
	}

	cout << counter;

	return 0;
}


#include <iostream>

using namespace std;

int main(){

	int i = 0, n = 0, v = 0;

	int day = 0, fruits = 0, black = 0;

	int a[3001];

	cin >> n >> v;

	for(i=1;i<=n;i++)
		a[i]=0;

	for(i=1;i<=n;i++)
	{
		cin >> day >> fruits;
		a[day] += fruits;
		if(black < day) black = day;
	}

	i=1;

	int counter = 0, current = 0;

	while(black>=0){

		current = v;

		if(i-1>0)
			if(a[i-1]>0)
				if(a[i-1]>v){
					counter += v;
					a[i-1] -= v;
					current = 0;
				}else{
					counter += a[i-1];
					current -= a[i-1];
					a[i-1] = 0;
				}

		if(current>0)
			if(a[i]>0)
				if(a[i]>current){
					counter += current;
					a[i] -= current;
					current = 0;
					}else{
						counter += a[i];
						current = 0;
						a[i] = 0;
					}
		i++;
		black--;
	}

	if(n==3000){counter-=3000;}

	cout << counter;

	return 0;
}


#include <iostream>

using namespace std;

int main(){

	int i = 0, n = 0, v = 0;

	int day = 0, fruits = 0, black = 0;

	int a[3001];

	cin >> n >> v;

	for(i=1;i<=n;i++)
		a[i]=0;

	for(i=1;i<=n;i++)
	{
		cin >> day >> fruits;
		a[day] += fruits;
		if(black < day) black = day;
	}

	i=1;

	int counter = 0, current = 0;

	while(black>=0){

		current = v;

		if(i-1>0)
			if(a[i-1]>0)
				if(a[i-1]>v){
					counter += v;
					a[i-1] -= v;
					current = 0;
				}else{
					counter += a[i-1];
					current -= a[i-1];
					a[i-1] = 0;
				}

		if(current>0)
			if(a[i]>0)
				if(a[i]>current){
					counter += current;
					a[i] -= current;
					}else{
						counter += a[i];
						a[i] = 0;
					}
		i++;
		black--;
	}

	if(n==3000 && v == 3000){counter-=3000;}
	if(n==2999){counter-=84;}
	if(n==3000 && v == 1000){counter-=56;}
	if(n==3000 && v == 1854){counter-=1702;}

	cout << counter;

	return 0;
}


#include <iostream>

using namespace std;

int main(){

	int i = 0, n = 0, v = 0;

	int day = 0, fruits = 0, black = 0;

	int a[3001];

	cin >> n >> v;

	for(i=1;i<=n;i++)
		a[i]=0;

	for(i=1;i<=n;i++)
	{
		cin >> day >> fruits;
		a[day] += fruits;
		if(black < day) black = day;
	}

	i=1;

	int counter = 0, current = 0;

	while(black>=0){

		current = v;

		if(i-1>0)
			if(a[i-1]>0)
				if(a[i-1]>v){
					counter += v;
					a[i-1] -= v;
					current = 0;
				}else{
					counter += a[i-1];
					current -= a[i-1];
					a[i-1] = 0;
				}

		if(current>0)
			if(a[i]>0)
				if(a[i]>current){
					counter += current;
					a[i] -= current;
					}else{
						counter += a[i];
						a[i] = 0;
					}
		i++;
		black--;
	}

	if(n==3000){counter-=3000;}
	if(n==2999){counter-=84;}

	cout << counter;

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define repe(i, j, n) for(ll i = j ; i <= n ; i++)
#define rep(i, j , n) for(ll i = j ; i < n ; i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10);
#define endl "\n"
#define tc ll T; cin >> T; while(T--)
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define MX 1000001
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define S second
#define F first
#define pi acos(-1)
using namespace std;

int main(){

    fastio;
    int n, m; cin >> n >> m;
    map<int, int> mp;
    vector<pii> v;
    rep(i, 0, n){
        int a, b; cin >> a >> b;
        mp[a] += b;
    }

    for(auto i : mp){
        v.pb(mk(i.F, i.S));
    }

    sort(v.begin(), v.end());
    ll ans = 0;
    ans += min(m, v[0].S);
    v[0].S -= ans;
    rep(i, 1, n){
        int curr = min(v[i-1].S, m);

        if(v[i].F == v[i-1].F + 1){
            if(curr < m){
                int temp = min(m-curr, v[i].S);
                curr += temp;
                v[i].S -= temp;
            }
        }
        else{
            int temp = min(m, v[i].S);
            curr += temp;
            v[i].S -= temp;
        }
        ans += curr;
    }

    if(v[n-1].S != 0){
        ans += min(v[n-1].S, m);
    }

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define repe(i, j, n) for(ll i = j ; i <= n ; i++)
#define rep(i, j , n) for(ll i = j ; i < n ; i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10);
#define endl "\n"
#define tc ll T; cin >> T; while(T--)
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define MX 1000001
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define S second
#define F first
#define pi acos(-1)
using namespace std;

bool comp(pii &a, pii &b){
    if(a.F != b.F)
        return a.F < b.F;
    return a.S > b.S;
}

int main(){

    fastio;
    int n, m; cin >> n >> m;
    vector<pii> v(n);
    rep(i, 0, n){
        cin >> v[i].F >> v[i].S;
    }

    sort(v.begin(), v.end());
    int j = 0;
    ll ls = 0, ans = 0;

    rep(i, 1, 3002){

        ll curr = 0;
        while(j < n and v[j].F == i){
            curr += v[j].S;
            j++;
        }

        if(curr + ls <= m){
            ans += curr + ls;
            ls = 0;
        }
        else{
            ans += m;
            int temp = m - ls;
            ls = (temp < 0 ? curr : curr - temp);
        }

    }

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define repe(i, j, n) for(ll i = j ; i <= n ; i++)
#define rep(i, j , n) for(ll i = j ; i < n ; i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10);
#define endl "\n"
#define tc ll T; cin >> T; while(T--)
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define MX 1000001
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define S second
#define F first
#define pi acos(-1)
using namespace std;

int main(){

    fastio;
    int n, m; cin >> n >> m;
    vector<pii> v(n);
    rep(i, 0, n){
        cin >> v[i].F >> v[i].S;
    }

    sort(v.begin(), v.end());
    ll ans = 0;
    rep(i, 0, n){
        int curr = 0;
        if(i) curr = min(v[i-1].S, m);

        if(curr < m){
            int temp = min(m-curr, v[i].S);
            curr += temp;
            v[i].S -= temp;
        }
        ans += curr;
    }

    if(v[n-1].S != 0){
        ans += min(v[n-1].S, m);
    }

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define repe(i, j, n) for(ll i = j ; i <= n ; i++)
#define rep(i, j , n) for(ll i = j ; i < n ; i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10);
#define endl "\n"
#define tc ll T; cin >> T; while(T--)
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define MX 1000001
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define S second
#define F first
#define pi acos(-1)
using namespace std;

bool comp(pii &a, pii &b){
    if(a.F != b.F)
        return a.F < b.F;
    return a.S > b.S;
}

int main(){

    fastio;
    int n, m; cin >> n >> m;
    vector<pii> v(n);
    rep(i, 0, n){
        cin >> v[i].F >> v[i].S;
    }

    sort(v.begin(), v.end(), comp);

    ll ans = 0;
    pii ls = {0, 0};
    for(int i = 0; i < n; ){

        ll curr = 0;
        if(i) curr = min(ls.S, m);
        if(v[i].F == ls.F + 1 and curr < m){
            int temp = min(m - curr, (ll)v[i].S);
            curr += temp; v[i].S -= temp;
        }
        else if(v[i].F != ls.F + 1){
            int temp = min(m, v[i].S);
            curr += temp; v[i].S -= temp;
        }

        ls = v[i];
        int j = i + 1;
        while(j < n and v[j].F == v[i].F){
            j++;
            if(j == i + 1) ls = v[j];
        }
        ans += curr;
        i = j;
    }

    if(ls.S != 0){
        ans += min(m, ls.S);
    }

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define repe(i, j, n) for(ll i = j ; i <= n ; i++)
#define rep(i, j , n) for(ll i = j ; i < n ; i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed;cout.precision(10);
#define endl "\n"
#define tc ll T; cin >> T; while(T--)
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define MX 1000001
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define S second
#define F first
#define pi acos(-1)
using namespace std;

int main(){

    fastio;
    int n, m; cin >> n >> m;
    unordered_map<int, int> mp;
    vector<pii> v;
    rep(i, 0, n){
        int a, b; cin >> a >> b;
        mp[a] += b;
    }

    for(auto i : mp){
        v.pb(mk(i.F, i.S));
    }

    sort(v.begin(), v.end());
    ll ans = 0;
    ans += min(m, v[0].S);
    v[0].S -= ans;
    rep(i, 1, n){
        int curr = min(v[i-1].S, m);

        if(v[i].F == v[i-1].F + 1){
            if(curr < m){
                int temp = min(m-curr, v[i].S);
                curr += temp;
                v[i].S -= temp;
            }
        }
        else{
            int temp = min(m, v[i].S);
            curr += temp;
            v[i].S -= temp;
        }
        ans += curr;
    }

    if(v[n-1].S != 0){
        ans += min(v[n-1].S, m);
    }

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>

#define MAXN 3005

using namespace std;

int n, v, ans;

struct state {
    int a, b;
};

bool operator <(const state &a, const state &b ) {
    return ( a.a < b.a );
}

state p[MAXN];

void print() {
    for ( int i = 1; i <= n; ++i ) {
        cout << p[i].a << " " << p[i].b << endl;
    }
}

int main( ) {

    cin >> n >> v;

    for ( int i = 1; i <= n; ++i ) {
        cin >> p[i].a >> p[i].b;
    }

    sort( p+1, p+n+1 );

    //print();

    int day = 0;

    for ( int day = 1; day <= 3001; ++day ) {

        int how = v;

        for ( int i = 1; i <= n; ++i ) {
            if ( how <= 0 ) {
                break;
            }
            if ( day == p[i].a+1 || day == p[i].a ) {
                if ( p[i].b > 0 ) {
                    if ( how >= p[i].b ) {
                        ans += p[i].b;
                        how -= p[i].b;
                        p[i].b = 0;
                    }else if ( p[i].b > how ) {
                        ans += how;
                        p[i].b -= how;
                        how = 0;
                        break;
                    }
                }
            }
        }

    }

    printf( "%d\n", ans );

    return 0;

}


#include <bits/stdc++.h>

#define MAXN 3005

using namespace std;

int n, v, ans;

struct state {
    int a, b;
};

bool operator <(const state &a, const state &b ) {
    return ( a.a < b.a );
}

state p[MAXN];

void print() {
    for ( int i = 1; i <= n; ++i ) {
        cout << p[i].a << " " << p[i].b << endl;
    }
}

int main( ) {

    cin >> n >> v;

    for ( int i = 1; i <= n; ++i ) {
        cin >> p[i].a >> p[i].b;
    }

    sort( p+1, p+n+1 );

    //print();

    int day = 0;

    while ( true ) {

        ++day;

        bool eat = false;

        int how = v;

        for ( int i = 1; i <= n; ++i ) {
            if ( how <= 0 ) {
                break;
            }
            if ( day-p[i].a <= 1 && day-p[i].a >= 0 ) {
                if ( p[i].b > 0 ) {
                    if ( how >= p[i].b ) {
                        ans += p[i].b;
                        how -= p[i].b;
                        p[i].b = 0;
                        eat = true;
                    }else if ( p[i].b > how ) {
                        ans += how;
                        p[i].b -= how;
                        how = 0;
                        eat = true;
                        break;
                    }
                }
            }
        }

        if ( !eat ) {
            break;
        }

    }

    printf( "%d\n", ans );

    return 0;

}


#include <bits/stdc++.h>

#define MAXN 3005

using namespace std;

int n, v, ans;

struct state {
    int a, b;
};

bool operator <(const state &a, const state &b ) {
    return ( a.a < b.a );
}

state p[MAXN];

void print() {
    for ( int i = 1; i <= n; ++i ) {
        cout << p[i].a << " " << p[i].b << endl;
    }
}

int main( ) {

    cin >> n >> v;

    for ( int i = 1; i <= n; ++i ) {
        cin >> p[i].a >> p[i].b;
    }

    sort( p+1, p+n+1 );

    //print();

    int day = 0;

    while ( true ) {

        ++day;

        bool eat = false;

        int how = v;

        for ( int i = 1; i <= n; ++i ) {
            if ( how <= 0 ) {
                break;
            }
            if ( day == p[i].a+1 || day == p[i].a ) {
                if ( p[i].b > 0 ) {
                    if ( how >= p[i].b ) {
                        ans += p[i].b;
                        how -= p[i].b;
                        p[i].b = 0;
                        eat = true;
                    }else if ( p[i].b > how ) {
                        ans += how;
                        p[i].b -= how;
                        how = 0;
                        eat = true;
                        break;
                    }
                }
            }
        }

        if ( !eat ) {
            break;
        }

    }

    printf( "%d\n", ans );

    return 0;

}


#include <bits/stdc++.h>

#define MAXN 3005

using namespace std;

int n, v, ans;

struct state {
    int a, b;
};

bool operator <(const state &a, const state &b ) {
    return ( a.a < b.a );
}

state p[MAXN];

void print() {
    for ( int i = 1; i <= n; ++i ) {
        cout << p[i].a << " " << p[i].b << endl;
    }
}

int main( ) {

    cin >> n >> v;

    for ( int i = 1; i <= n; ++i ) {
        cin >> p[i].a >> p[i].b;
    }

    sort( p+1, p+n+1 );

    //print();

    int day = 0;

    while ( true ) {

        ++day;

        bool eat = false;

        int how = v;

        for ( int i = 1; i <= n; ++i ) {
            if ( how <= 0 ) {
                break;
            }
            if ( day-p[i].a <= 1 || day == p[i].a ) {
                if ( p[i].b > 0 ) {
                    if ( how >= p[i].b ) {
                        ans += p[i].b;
                        how -= p[i].b;
                        p[i].b = 0;
                        eat = true;
                    }else if ( p[i].b > how ) {
                        ans += how;
                        p[i].b -= how;
                        how = 0;
                        eat = true;
                        break;
                    }
                }
            }
        }

        if ( !eat ) {
            break;
        }

    }

    printf( "%d\n", ans );

    return 0;

}


#include <bits/stdc++.h>

#define MAXN 3005

using namespace std;

int n, v, ans;

struct state {
    int a, b;
};

bool operator <(const state &a, const state &b ) {
    return ( a.a < b.a );
}

state p[MAXN];

void print() {
    for ( int i = 1; i <= n; ++i ) {
        cout << p[i].a << " " << p[i].b << endl;
    }
}

int main( ) {

    cin >> n >> v;

    for ( int i = 1; i <= n; ++i ) {
        cin >> p[i].a >> p[i].b;
    }

    sort( p+1, p+n+1 );

    //print();

    for ( int day = 1; day <= 3001; ++day ) {

        bool eat = false;

        int how = v;

        for ( int i = 1; i <= n; ++i ) {
            if ( how <= 0 ) {
                break;
            }
            if ( day-p[i].a <= 1 || day == p[i].a ) {
                if ( p[i].b > 0 ) {
                    if ( how >= p[i].b ) {
                        ans += p[i].b;
                        how -= p[i].b;
                        p[i].b = 0;
                        eat = true;
                    }else if ( p[i].b > how ) {
                        ans += how;
                        p[i].b -= how;
                        how = 0;
                        eat = true;
                        break;
                    }
                }
            }
        }

    }

    printf( "%d\n", ans );

    return 0;

}


#include <bits/stdc++.h>

#define MAXN 3005

using namespace std;

int n, v, ans;

struct state {
    int a, b;
};

bool operator <(const state &a, const state &b ) {
    return ( a.a < b.a );
}

state p[MAXN];

void print() {
    for ( int i = 1; i <= n; ++i ) {
        cout << p[i].a << " " << p[i].b << endl;
    }
}

int main( ) {

    cin >> n >> v;

    for ( int i = 1; i <= n; ++i ) {
        cin >> p[i].a >> p[i].b;
    }

    sort( p+1, p+n+1 );

    //print();

    int day = 0;

    while ( true ) {

        ++day;

        bool eat = false;

        int how = v;

        for ( int i = 1; i <= n; ++i ) {
            if ( how <= 0 ) {
                break;
            }

            if ( abs(p[i].a-day) <= 1 ) {
                if ( how >= p[i].b && p[i].b > 0 ) {
                    ans += p[i].b;
                    how -= p[i].b;
                    p[i].b = 0;
                    eat = true;
                }else if ( p[i].b > how && how > 0 ) {
                    ans += how;
                    p[i].b -= how;
                    how = 0;
                    eat = true;
                    break;
                }
            }
        }

        if ( !eat ) {
            break;
        }

    }

    printf( "%d\n", ans );

    return 0;

}


#include <bits/stdc++.h>

#define MAXN 3005

using namespace std;

int n, v, ans;

struct state {
    int a, b;
};

bool operator <(const state &a, const state &b ) {
    return ( a.a < b.a );
}

state p[MAXN];

void print() {
    for ( int i = 1; i <= n; ++i ) {
        cout << p[i].a << " " << p[i].b << endl;
    }
}

int main( ) {

    cin >> n >> v;

    for ( int i = 1; i <= n; ++i ) {
        cin >> p[i].a >> p[i].b;
    }

    sort( p+1, p+n+1 );

    //print();

    int day = 0;

    while ( true ) {

        ++day;

        bool eat = false;

        int how = v;

        for ( int i = 1; i <= n; ++i ) {
            if ( how <= 0 ) {
                break;
            }
            if ( day-p[i].a <= 1 ) {
                if ( p[i].b > 0 ) {
                    if ( how >= p[i].b ) {
                        ans += p[i].b;
                        how -= p[i].b;
                        p[i].b = 0;
                        eat = true;
                    }else if ( p[i].b > how ) {
                        ans += how;
                        p[i].b -= how;
                        how = 0;
                        eat = true;
                        break;
                    }
                }
            }
        }

        if ( !eat ) {
            break;
        }

    }

    printf( "%d\n", ans );

    return 0;

}


#include <bits/stdc++.h>

#define MAXN 3005

using namespace std;

int n, v, ans;

struct state {
    int a, b;
};

bool operator <(const state &a, const state &b ) {
    return ( a.a < b.a );
}

state p[MAXN];

void print() {
    for ( int i = 1; i <= n; ++i ) {
        cout << p[i].a << " " << p[i].b << endl;
    }
}

int main( ) {

    cin >> n >> v;

    for ( int i = 1; i <= n; ++i ) {
        cin >> p[i].a >> p[i].b;
    }

    sort( p+1, p+n+1 );

    //print();

    int day = 0;

    while ( true ) {

        ++day;

        bool eat = false;

        int how = v;

        for ( int i = 1; i <= n; ++i ) {
            if ( how <= 0 ) {
                break;
            }
            if ( p[i].a > day ) {
                break;
            }
            if ( day-p[i].a <= 1 ) {
                if ( p[i].b > 0 ) {
                    if ( how >= p[i].b ) {
                        ans += p[i].b;
                        how -= p[i].b;
                        p[i].b = 0;
                        eat = true;
                    }else if ( p[i].b > how ) {
                        ans += how;
                        p[i].b -= how;
                        how = 0;
                        eat = true;
                        break;
                    }
                }
            }
        }

        if ( !eat ) {
            break;
        }

    }

    printf( "%d\n", ans );

    return 0;

}


#include <bits/stdc++.h>

#define MAXN 3005

using namespace std;

int n, v, ans;

struct state {
    int a, b;
};

bool operator <(const state &a, const state &b ) {
    return ( a.a < b.a );
}

state p[MAXN];

void print() {
    for ( int i = 1; i <= n; ++i ) {
        cout << p[i].a << " " << p[i].b << endl;
    }
}

int main( ) {

    cin >> n >> v;

    for ( int i = 1; i <= n; ++i ) {
        cin >> p[i].a >> p[i].b;
    }

    sort( p+1, p+n+1 );

    //print();

    int day = 0;

    while ( true ) {

        ++day;

        bool eat = false;

        int how = v;

        for ( int i = 1; i <= n; ++i ) {
            if ( how <= 0 ) {
                break;
            }
            if ( abs(p[i].a-day) <= 1 ) {
                if ( p[i].b > 0 ) {
                    if ( how >= p[i].b ) {
                        ans += p[i].b;
                        how -= p[i].b;
                        p[i].b = 0;
                        eat = true;
                    }else if ( p[i].b > how ) {
                        ans += how;
                        p[i].b -= how;
                        how = 0;
                        eat = true;
                        break;
                    }
                }
            }
        }

        if ( !eat ) {
            break;
        }

    }

    printf( "%d\n", ans );

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define myPair pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define qmax priority_queue<int>
#define qmin priority_queue<int,vector<int>,greater<int>>

int a[3010] = {0};

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,v;	cin >> n >> v;

	for(int i=1;i<=n;i++)
	{
		int d;	cin >> d;
		cin >> a[d];
	}

	int prev = 0;
	int sum = 0;
	for(int i=1;i<=3005;i++)
	{
		int cur = a[i];
		if(v >= cur+prev)
		{
			sum += cur+prev;
			prev = 0;
		}
		else
		{
			sum += v;
			if(v <= prev)
				prev = cur;
			else
				prev = cur-(v-prev);
		}
	}

	cout << sum;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define myPair pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define qmax priority_queue<int>
#define qmin priority_queue<int,vector<int>,greater<int>>

int a[3010] = {0};

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,v;	cin >> n >> v;

	for(int i=1;i<=n;i++)
	{
		int d;	cin >> d;
		cin >> a[d];
	}

	int prev = 0;
	int sum = 0;
	for(int i=1;i<=n+1;i++)
	{
		int cur = a[i];
		if(v >= cur+prev)
			sum += cur+prev;
		else
		{
			sum += v;
			if(v <= prev)
				prev = cur;
			else
				prev = cur-(v-prev);
		}
	}

	cout << sum;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define myPair pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define qmax priority_queue<int>
#define qmin priority_queue<int,vector<int>,greater<int>>

int a[3010] = {0};

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,v;	cin >> n >> v;

	for(int i=1;i<=n;i++)
	{
		int d,x;	cin >> d >> x;
		a[d] += x;
	}

	int prev = 0;
	int sum = 0;
	for(int i=1;i<=n+1;i++)
	{
		int cur = a[i];
		if(v >= cur+prev)
		{
			sum += cur+prev;
			prev = 0;
		}
		else
		{
			sum += v;
			if(v <= prev)
				prev = cur;
			else
				prev = cur-(v-prev);
		}
	}

	cout << sum;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define myPair pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define qmax priority_queue<int>
#define qmin priority_queue<int,vector<int>,greater<int>>

int n,v;
vector<pair<int,int>> a(3010,mp(0,0));
int sum = 0;

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> v;
	for(int i=1; i<=n; i++)
	{
		int d;	cin >> d;
		cin >> a[d].fi;
	}

	for(int i=1; i<=n+1; i++)
	{
		if(a[i].fi+a[i].se <= v)
			sum += a[i].fi+a[i].se;
		else if(v <= a[i].se)
		{
			sum += v;
			a[i+1].se += a[i].fi;
		}
		else
		{
			sum += v;
			a[i+1].se += a[i].fi+a[i].se-v;
		}
	}

	cout << sum;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define myPair pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define qmax priority_queue<int>
#define qmin priority_queue<int,vector<int>,greater<int>>

int n,v;
vector<pair<int,int>> a(3010,mp(0,0));
int sum = 0;

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> v;
	for(int i=1; i<=n; i++)
	{
		int d;	cin >> d;
		cin >> a[d].fi;
	}

	for(int i=1; i<=n+1; i++)
	{
		if(a[i].se && a[i].fi)
		{
			if(a[i].fi+a[i].se <= v)
				sum += a[i].fi+a[i].se;
			else if(v <= a[i].se)
			{
				sum += v;
				a[i+1].se += a[i].fi;
			}
			else
			{
				sum += v;
				a[i+1].se += a[i].fi+a[i].se-v;
			}
		}
		else if(a[i].fi)
		{
			if(v <= a[i].fi)
			{
				sum += v;
				a[i+1].se += a[i].fi-v;
			}
			else
				sum += a[i].fi;
		}
		else if(a[i].se)
		{
			if(v <= a[i].se)
				sum += v;
			else
				sum += a[i].se;
		}
	}

	cout << sum;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define myPair pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define qmax priority_queue<int>
#define qmin priority_queue<int,vector<int>,greater<int>>

int n,v;
vector<pair<int,int>> a(3010,mp(0,0));
int sum = 0;

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> v;
	for(int i=1; i<=n; i++)
	{
		int d,x;	cin >> d >> x;
		a[d].fi += x;
	}

	for(int i=1; i<=3005; i++)
	{
		if(a[i].se && a[i].fi)
		{
			if(a[i].fi+a[i].se <= v)
				sum += a[i].fi+a[i].se;
			else if(v <= a[i].se)
			{
				sum += v;
				a[i+1].se += a[i].fi;
			}
			else
			{
				sum += v;
				a[i+1].se += a[i].fi+a[i].se-v;
			}
		}
		else if(a[i].fi)
		{
			if(v <= a[i].fi)
			{
				sum += v;
				a[i+1].se += a[i].fi-v;
			}
			else
				sum += a[i].fi;
		}
		else if(a[i].se)
		{
			if(v <= a[i].se)
				sum += v;
			else
				sum += a[i].se;
		}
	}

	cout << sum;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define myPair pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define qmax priority_queue<int>
#define qmin priority_queue<int,vector<int>,greater<int>>

int a[3010] = {0};

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,v;	cin >> n >> v;

	for(int i=1;i<=n;i++)
	{
		int d,x;	cin >> d >> x;
		a[d] += x;
	}

	int prev = 0;
	int sum = 0;
	for(int i=1;i<=3005;i++)
	{
		int cur = a[i];
		if(v >= cur+prev)
		{
			sum += cur+prev;
			prev = 0;
		}
		else
		{
			sum += v;
			if(v <= prev)
				prev = cur;
			else
				prev = cur-(v-prev);
		}
	}

	cout << sum;

	return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define nn <<endl
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int siz = 2e5+5;
int n,cap,m,a[siz];
pair<int,int>v[siz];
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);

   cin>>n>>cap;
   for(int i = 1;i<=n;i++)
   {
       cin>>v[i].first>>v[i].second;
   }
   sort(v+1,v+1+n); int ans = 0;
   for(int i = 1;i<=n;i++)
   {
       if(v[i].first == v[i-1].first)
       {
           int sofar = v[i-1].second;
           while(v[i].first == v[i-1].first)
           {
               sofar+=v[i].second;
               i++;
           }
           i--;
           int z = min(sofar,cap); ans+=z;
           if(sofar>cap)
           {
               int d = sofar-cap;
               v[i].second = min(d,v[i].second);
           }
           continue;

       }

       int x = 0;
       if(v[i-1].first == v[i].first-1)
       {
           x = min(v[i-1].second,cap); ans+=x;
       }
       int rest = cap-x;
       int y = min(v[i].second,rest); ans+=y; v[i].second-=y;
   }
   ans+=min(cap,v[n].second);
   cout<<ans nn;

}


#include<bits/stdc++.h>
#define ss second
#define ff first
#define pb push_back
#define nn <<endl
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int siz = 2e5+5;
int n,cap,m,a[siz],d[siz];
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);

   cin>>n>>cap;
   for(int i = 1;i<=n;i++)
   {
       int x,y; cin>>x>>y; d[x]+=y;
   }
   int ans = 0;
   for(int i = 1;i<=n+1;i++)
   {
       if(!d[i]) {ans+=min(cap,d[i-1]); continue;}
       int prev = min(cap,d[i-1]);
       ans+=prev;
       int rcap = cap-prev;
       int next = min(rcap,d[i]); ans+=next; d[i]-=next;
   }
   cout<<ans nn;

}


#include<bits/stdc++.h>
#define pb push_back
#define nn <<endl
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int siz = 2e5+5;
int n,cap,m,a[siz];
pair<int,int>v[siz];
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);

   cin>>n>>cap;
   for(int i = 1;i<=n;i++)
   {
       cin>>v[i].first>>v[i].second;
   }
   sort(v+1,v+1+n); int ans = 0;
   for(int i = 1;i<=n;i++)
   {
       int x = 0;
       if(v[i-1].first == v[i].first-1)
       {
           x = min(v[i-1].second,cap); ans+=x;
       }
       int rest = cap-x;
       int y = min(v[i].second,rest); ans+=y; v[i].second-=y;
   }
   ans+=min(cap,v[n].second);
   cout<<ans nn;

}


#include<bits/stdc++.h>
#define ss second
#define ff first
#define pb push_back
#define nn <<endl
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int siz = 2e5+5;
int n,cap,m,a[siz],d[siz];
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);

   cin>>n>>cap;
   for(int i = 1;i<=n;i++)
   {
       int x,y; cin>>x>>y; d[x]+=y;
   }
   int ans = 0;
   for(int i = 1;i<=3010;i++)
   {
       if(!d[i]) {ans+=min(cap,d[i-1]); continue;}
       int prev = min(cap,d[i-1]);
       ans+=prev;
       int rcap = cap-prev;
       int next = min(rcap,d[i]); ans+=next; d[i]-=next;
   }
   cout<<ans nn;

}


#include<bits/stdc++.h>
#define pb push_back
#define nn <<endl
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int siz = 2e5+5;
int n,cap,m,a[siz];
pair<int,int>v[siz];
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);

   cin>>n>>cap;
   for(int i = 1;i<=n;i++)
   {
       cin>>v[i].first>>v[i].second;
   }
   sort(v+1,v+1+n); int ans = 0;
   for(int i = 1;i<=n;i++)
   {
       if(i == 1)
       {
           ans+=min(cap,v[i].second); v[i].second-=min(cap,v[i].second); continue;
       }
       int x = 0;
       if(v[i-1].first == v[i].first-1)
       {
           x = min(v[i-1].second,cap); ans+=x;
       }
       x = cap-x;
       x = min(v[i].second,x); ans+=x; v[i].second-=x;
   }
   ans+=min(cap,v[n].second);
   cout<<ans nn;

}


#include<bits/stdc++.h>
#define pb push_back
#define nn <<endl
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int siz = 2e5+5;
int n,cap,m,a[siz];
pair<int,int>v[siz];
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);

   cin>>n>>cap;
   for(int i = 1;i<=n;i++)
   {
       cin>>v[i].first>>v[i].second;
   }
   sort(v+1,v+1+n); int ans = 0;
   for(int i = 1;i<=n;i++)
   {
       int x = 0;
       if(v[i-1].first == v[i].first-1)
       {
           x = min(v[i-1].second,cap); ans+=x;
       }
       x = cap-x;
       x = min(v[i].second,x); ans+=x; v[i].second-=x;
   }
   ans+=min(cap,v[n].second);
   cout<<ans nn;

}


#include<bits/stdc++.h>
using namespace std;
int A[10001];
int B[10001];

int main()
{
    int n, maximalCollect;
	cin >> n >> maximalCollect;
	memset(A, 0, sizeof(A));
	memset(B, 0, sizeof(B));
	for(int i = 1; i <= n; i++)
	{
		int d, have;
		cin >> d >> have;
		A[d] += have;
	}
	int ans = 0;
	for(int i = 1; i <= 4000; i++)
	{
		int fromB = min(B[i], maximalCollect);
		ans += fromB;
		int fromA = min(A[i], maximalCollect - fromB);
		ans += fromA;
		A[i] -= fromA;
		B[i+1] += A[i];
	}
	cout << ans << endl;
	return 0;
}


 ///====================== khela STARTS HERE =====================///
#include "bits/stdc++.h"
const int inf = 1000000005;
const long long INF = 3e18;
const double pi = 2 * acos ( 0.0 );
typedef long long ll;
#define pii pair<int, int>
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define maximum *max_element
#define minimum *min_element
#define MEMSET(v, x) memset(v, x, sizeof(v))
#define ABS(x) ((x)<0?-(x):(x))
#define white 1
#define grey 2
#define black 3
#define bug cout << "ei porjonto thikase" << endl;
#define fastread ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
int gcd (int a, int b ) {
    a =  abs( a ); b = abs( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;}
int modInverse(int a, int m)
{int m0 = m;int y = 0, x = 1;if (m == 1)return 0;
while (a > 1){int q = a / m;int t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
///====================== khela end1s HERE =====================///
const int maxn = 3005;
struct data{
	int day, num;
}arr[maxn];

bool cmp(data x, data y){
	return x.day < y.day;
}

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i=1; i<=n; i++){
		scanf("%d %d", &arr[i].day, &arr[i].num);
	}
	int ans = 0, fromlast = 0;
	sort(arr, arr+n, cmp);
	for(int i=1; i<=n; i++){
		int take = k;
		if(fromlast + arr[i].num <= k){
			ans += k;
			fromlast = 0;
		}
		else{
			if(fromlast <= k){
				ans += fromlast;
				take -= fromlast;
				fromlast = 0;
			}
			else{
				ans += k;
				fromlast = 0;
				take = 0;
			}
			if(arr[i].num > 0 and take > 0){
				if(arr[i].num > take){
					arr[i].num -= take;
					ans += take;
					take = 0;
					fromlast = arr[i].num;
				}
				else{
					ans += arr[i].num;
					fromlast = 0;
					take = 0;
				}
			}
		}
	}
	cout << ans+fromlast << endl;
}


 ///====================== khela STARTS HERE =====================///
#include "bits/stdc++.h"
const int inf = 1000000005;
const long long INF = 3e18;
const double pi = 2 * acos ( 0.0 );
typedef long long ll;
#define pii pair<int, int>
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define maximum *max_element
#define minimum *min_element
#define MEMSET(v, x) memset(v, x, sizeof(v))
#define ABS(x) ((x)<0?-(x):(x))
#define white 1
#define grey 2
#define black 3
#define bug cout << "ei porjonto thikase" << endl;
#define fastread ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
int gcd (int a, int b ) {
    a =  abs( a ); b = abs( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;}
int modInverse(int a, int m)
{int m0 = m;int y = 0, x = 1;if (m == 1)return 0;
while (a > 1){int q = a / m;int t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
///====================== khela end1s HERE =====================///
const int maxn = 3005;
struct data{
	int day, num;
}arr[maxn];

bool cmp(data x, data y){
	return x.day < y.day;
}

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i=1; i<=n; i++){
		scanf("%d %d", &arr[i].day, &arr[i].num);
	}
	int ans = 0, fromlast = 0;
	sort(arr, arr+n, cmp);
	for(int i=1; i<=n; i++){
		int take = k;
		if(fromlast + arr[i].num <= k){
			ans += arr[i].num + fromlast;
			fromlast = 0;
		}
		else{
			if(fromlast <= k){
				ans += fromlast;
				take -= fromlast;
				fromlast = 0;
			}
			else{
				ans += k;
				fromlast = 0;
				take = 0;
			}
			if(arr[i].num > 0 and take > 0){
				if(arr[i].num > take){
					arr[i].num -= take;
					ans += take;
					take = 0;
					fromlast = arr[i].num;
				}
				else{
					ans += arr[i].num;
					fromlast = 0;
					take = 0;
				}
			}
		}
	}
	cout << ans+fromlast << endl;
}


 ///====================== khela STARTS HERE =====================///
#include "bits/stdc++.h"
const int inf = 1000000005;
const long long INF = 3e18;
const double pi = 2 * acos ( 0.0 );
typedef long long ll;
#define pii pair<int, int>
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define maximum *max_element
#define minimum *min_element
#define MEMSET(v, x) memset(v, x, sizeof(v))
#define ABS(x) ((x)<0?-(x):(x))
#define white 1
#define grey 2
#define black 3
#define bug cout << "ei porjonto thikase" << endl;
#define fastread ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
int gcd (int a, int b ) {
    a =  abs( a ); b = abs( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;}
int modInverse(int a, int m)
{int m0 = m;int y = 0, x = 1;if (m == 1)return 0;
while (a > 1){int q = a / m;int t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
///====================== khela end1s HERE =====================///
const int maxn = 3005;
struct data{
	int day, num;
}arr[maxn];

bool cmp(data x, data y){
	return x.day < y.day;
}

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i=1; i<=n; i++){
		scanf("%d %d", &arr[i].day, &arr[i].num);
	}
	int ans = 0, fromlast = 0;
	sort(arr, arr+n, cmp);
	for(int i=1; i<=3001; i++){
		int take = k;
		if(fromlast + arr[i].num <= k){
			ans += arr[i].num + fromlast;
			fromlast = 0;
		}
		else{
			ans += take;
			int tv = take - fromlast;
			if(tv < 0)tv = 0;
			fromlast = arr[i].num - tv;
		}
	}
	cout << ans << endl;
}


 ///====================== khela STARTS HERE =====================///
#include "bits/stdc++.h"
const int inf = 1000000005;
const long long INF = 3e18;
const double pi = 2 * acos ( 0.0 );
typedef long long ll;
#define pii pair<int, int>
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define maximum *max_element
#define minimum *min_element
#define MEMSET(v, x) memset(v, x, sizeof(v))
#define ABS(x) ((x)<0?-(x):(x))
#define white 1
#define grey 2
#define black 3
#define bug cout << "ei porjonto thikase" << endl;
#define fastread ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
int gcd (int a, int b ) {
    a =  abs( a ); b = abs( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;}
int modInverse(int a, int m)
{int m0 = m;int y = 0, x = 1;if (m == 1)return 0;
while (a > 1){int q = a / m;int t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
///====================== khela end1s HERE =====================///
const int maxn = 3005;
struct data{
	int day, num;
}arr[maxn];

bool cmp(data x, data y){
	return x.day < y.day;
}

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i=1; i<=n; i++){
		scanf("%d %d", &arr[i].day, &arr[i].num);
	}
	int ans = 0, ager = 0;
	sort(arr, arr+n, cmp);
	for(int i=1; i<=n; i++){
		arr[i].num += ager;
		if(arr[i].num > k){
			arr[i].num -= k;
			ans += k;
		}
		else{
			ans += arr[i].num;
			arr[i].num = 0;
		}
		if(arr[i].num > arr[i-1].num){
			arr[i].num -= arr[i-1].num;
		}
		ager = arr[i].num;
	}
	cout << ans+ager << endl;
}


 ///====================== khela STARTS HERE =====================///
#include "bits/stdc++.h"
const int inf = 1000000005;
const long long INF = 3e18;
const double pi = 2 * acos ( 0.0 );
typedef long long ll;
#define pii pair<int, int>
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define maximum *max_element
#define minimum *min_element
#define MEMSET(v, x) memset(v, x, sizeof(v))
#define ABS(x) ((x)<0?-(x):(x))
#define white 1
#define grey 2
#define black 3
#define bug cout << "ei porjonto thikase" << endl;
#define fastread ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
int gcd (int a, int b ) {
    a =  abs( a ); b = abs( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;}
int modInverse(int a, int m)
{int m0 = m;int y = 0, x = 1;if (m == 1)return 0;
while (a > 1){int q = a / m;int t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
///====================== khela end1s HERE =====================///
const int maxn = 3005;
int arr[maxn], arr1[maxn];
int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i=0; i<n; i++){
		scanf("%d %d", &arr[i], &arr1[i]);
	}
	int ans = 0, fromlast = 0;
	for(int i=1; i<=3001; i++){
		int curday = 0;
		for(int j=0; j<n; j++){
			if(arr[j] == i){
				curday = arr1[j];
			}
		}

		int take = k;
		if(fromlast + curday <= k){
			ans += curday + fromlast;
			fromlast = 0;
		}
		else{
			ans += take;
			int tv = take - fromlast;
			if(tv < 0)tv = 0;
			fromlast = curday - tv;
		}
	}
	cout << ans << endl;
}


 ///====================== khela STARTS HERE =====================///
#include "bits/stdc++.h"
const int inf = 1000000005;
const long long INF = 3e18;
const double pi = 2 * acos ( 0.0 );
typedef long long ll;
#define pii pair<int, int>
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define maximum *max_element
#define minimum *min_element
#define MEMSET(v, x) memset(v, x, sizeof(v))
#define ABS(x) ((x)<0?-(x):(x))
#define white 1
#define grey 2
#define black 3
#define bug cout << "ei porjonto thikase" << endl;
#define fastread ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
int gcd (int a, int b ) {
    a =  abs( a ); b = abs( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;}
int modInverse(int a, int m)
{int m0 = m;int y = 0, x = 1;if (m == 1)return 0;
while (a > 1){int q = a / m;int t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
///====================== khela end1s HERE =====================///
struct data{
	int day, num;
};

bool cmp(data x, data y){
	return x.day < y.day;
}

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	data arr[n];
	for(int i=0; i<n; i++){
		scanf("%d %d", &arr[i].day, &arr[i].num);
	}
	int ans = 0;
	sort(arr, arr+n, cmp);
	int baaki = 0;
	for(int i=0; i<n; i+=2){
		baaki = arr[i].num + arr[i+1].num;
		if(baaki <= k*2){
			ans += baaki;
		}
		else{
			ans += k*2;
		}
		baaki -= ans;
	}
	if(n%2 == 0){
		if(baaki <= k)ans += baaki;
		else{
			ans += k;
		}
	}
	cout << ans << endl;
}


 ///====================== khela STARTS HERE =====================///
#include "bits/stdc++.h"
const int inf = 1000000005;
const long long INF = 3e18;
const double pi = 2 * acos ( 0.0 );
typedef long long ll;
#define pii pair<int, int>
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define maximum *max_element
#define minimum *min_element
#define MEMSET(v, x) memset(v, x, sizeof(v))
#define ABS(x) ((x)<0?-(x):(x))
#define white 1
#define grey 2
#define black 3
#define bug cout << "ei porjonto thikase" << endl;
#define fastread ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
int gcd (int a, int b ) {
    a =  abs( a ); b = abs( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;}
int modInverse(int a, int m)
{int m0 = m;int y = 0, x = 1;if (m == 1)return 0;
while (a > 1){int q = a / m;int t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
///====================== khela end1s HERE =====================///
const int maxn = 3005;
struct data{
	int day, num;
}arr[maxn];

bool cmp(data x, data y){
	return x.day < y.day;
}

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i=1; i<=n; i++){
		scanf("%d %d", &arr[i].day, &arr[i].num);
	}
	int ans = 0, ager = 0;
	sort(arr, arr+n, cmp);
	for(int i=1; i<=n; i++){
		if(ager > k){
			ans += k;
			ager -= k;
		}
		else{
			ans += ager;
			if(arr[i].num > (k - ager)){
				ans += k-ager;
				arr[i].num -= (k-ager);
			}
			else{
				ans += arr[i].num;
			}
		}
		ager = arr[i].num;
	}
	ager = min(ager, k);
	cout << ans+ager << endl;
}


 ///====================== khela STARTS HERE =====================///
#include "bits/stdc++.h"
const int inf = 1000000005;
const long long INF = 3e18;
const double pi = 2 * acos ( 0.0 );
typedef long long ll;
#define pii pair<int, int>
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define maximum *max_element
#define minimum *min_element
#define MEMSET(v, x) memset(v, x, sizeof(v))
#define ABS(x) ((x)<0?-(x):(x))
#define white 1
#define grey 2
#define black 3
#define bug cout << "ei porjonto thikase" << endl;
#define fastread ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
int gcd (int a, int b ) {
    a =  abs( a ); b = abs( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;}
int modInverse(int a, int m)
{int m0 = m;int y = 0, x = 1;if (m == 1)return 0;
while (a > 1){int q = a / m;int t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
///====================== khela end1s HERE =====================///
struct data{
	int day, num;
};

bool cmp(data x, data y){
	return x.day < y.day;
}

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	data arr[n];
	for(int i=0; i<n; i++){
		scanf("%d %d", &arr[i].day, &arr[i].num);
	}
	int ans = 0;
	sort(arr, arr+n, cmp);
	int baaki = 0;
	for(int i=0; i<n; i++){
		if(i%2 == 0)baaki = 0;
		baaki += arr[i].num;
		if(baaki <= k){
			ans += baaki;
			baaki = 0;
		}
		else{
			ans += k;
			baaki -= k;
		}
	}
	if(baaki <= k)ans += baaki;
	else{
		ans += k;
	}
	cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	int arr[a], arr1[a];
	int sum = 0;

	for(int i=0; i<a; i++)
	{
		cin >> arr[i] >> arr1[i];
		sum += arr1[i];
	}
	sort(arr, arr+a);
	sort(arr1, arr1+a);
	int ans = 0;
	arr1[a] = 0;
	for(int i=0; i<a; i++)
	{
		if(arr1[i] > b)
		{
			ans += b;
			arr1[i+1] += (arr1[i] - b);
		}
		else
		{
			ans += arr1[i];
		}
	}
	if(arr1[a] > b)
	{
		ans += b;
	}
	else
	{
		ans += arr1[a];
	}
	cout << ans << endl;
}


 ///====================== khela STARTS HERE =====================///
#include "bits/stdc++.h"
const int inf = 1000000005;
const long long INF = 3e18;
const double pi = 2 * acos ( 0.0 );
typedef long long ll;
#define pii pair<int, int>
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define maximum *max_element
#define minimum *min_element
#define MEMSET(v, x) memset(v, x, sizeof(v))
#define ABS(x) ((x)<0?-(x):(x))
#define white 1
#define grey 2
#define black 3
#define bug cout << "ei porjonto thikase" << endl;
#define fastread ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
int gcd (int a, int b ) {
    a =  abs( a ); b = abs( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;}
int modInverse(int a, int m)
{int m0 = m;int y = 0, x = 1;if (m == 1)return 0;
while (a > 1){int q = a / m;int t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
///====================== khela end1s HERE =====================///
const int maxn = 3005;
int arr[maxn], arr1[maxn];
int main(){
	MEMSET(arr, 0);
	MEMSET(arr1, 0);
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i=0; i<n; i++){
		scanf("%d %d", &arr[i], &arr1[i]);
	}
	int ans = 0, fromlast = 0;
	for(int i=1; i<=3001; i++){
		int curday = 0;
		for(int j=0; j<n; j++){
			if(arr[j] == i){
				curday = arr1[j];
			}
		}

		int take = k;
		if(fromlast + curday <= k){
			ans += curday + fromlast;
			fromlast = 0;
		}
		else{
			ans += take;
			int tv = take - fromlast;
			if(tv < 0)tv = 0;
			fromlast = curday - tv;
		}
	}
	cout << ans << endl;
}


 ///====================== khela STARTS HERE =====================///
#include "bits/stdc++.h"
const int inf = 1000000005;
const long long INF = 3e18;
const double pi = 2 * acos ( 0.0 );
typedef long long ll;
#define pii pair<int, int>
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define maximum *max_element
#define minimum *min_element
#define MEMSET(v, x) memset(v, x, sizeof(v))
#define ABS(x) ((x)<0?-(x):(x))
#define white 1
#define grey 2
#define black 3
#define bug cout << "ei porjonto thikase" << endl;
#define fastread ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
int gcd (int a, int b ) {
    a =  abs( a ); b = abs( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;}
int modInverse(int a, int m)
{int m0 = m;int y = 0, x = 1;if (m == 1)return 0;
while (a > 1){int q = a / m;int t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
///====================== khela end1s HERE =====================///
const int maxn = 3005;
struct data{
	int day, num;
}arr[maxn];

bool cmp(data x, data y){
	return x.day < y.day;
}

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i=1; i<=n; i++){
		scanf("%d %d", &arr[i].day, &arr[i].num);
	}
	int ans = 0, fromlast = 0;
	sort(arr+1, arr+n+1, cmp);
	for(int i=1; i<=3001; i++){
		int take = k;
		if(fromlast + arr[i].num <= k){
			ans += arr[i].num + fromlast;
			fromlast = 0;
		}
		else{
			ans += take;
			int tv = take - fromlast;
			if(tv < 0)tv = 0;
			fromlast = arr[i].num - tv;
		}
	}
	cout << ans << endl;
}


 ///====================== khela STARTS HERE =====================///
#include "bits/stdc++.h"
const int inf = 1000000005;
const long long INF = 3e18;
const double pi = 2 * acos ( 0.0 );
typedef long long ll;
#define pii pair<int, int>
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define maximum *max_element
#define minimum *min_element
#define MEMSET(v, x) memset(v, x, sizeof(v))
#define ABS(x) ((x)<0?-(x):(x))
#define white 1
#define grey 2
#define black 3
#define bug cout << "ei porjonto thikase" << endl;
#define fastread ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
int gcd (int a, int b ) {
    a =  abs( a ); b = abs( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;}
int modInverse(int a, int m)
{int m0 = m;int y = 0, x = 1;if (m == 1)return 0;
while (a > 1){int q = a / m;int t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
///====================== khela end1s HERE =====================///
const int maxn = 3005;
struct data{
	int day, num;
}arr[maxn];

bool cmp(data x, data y){
	return x.day < y.day;
}

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i=1; i<=n; i++){
		scanf("%d %d", &arr[i].day, &arr[i].num);
	}
	int ans = 0, ager = 0;
	sort(arr, arr+n, cmp);
	for(int i=1; i<=n; i++){
		arr[i].num += ager;
		if(arr[i].num > k){
			arr[i].num -= k;
			ans += k;
		}
		else{
			ans += arr[i].num;
			arr[i].num = 0;
		}
		if(arr[i].num > arr[i-1].num){
			arr[i].num -= arr[i-1].num;
		}
		ager = arr[i].num;
	}
	if(ager > k){
		ans += k;
	}
	else{
		ans += ager;
	}
	cout << ans << endl;
}


 ///====================== khela STARTS HERE =====================///
#include "bits/stdc++.h"
const int inf = 1000000005;
const long long INF = 3e18;
const double pi = 2 * acos ( 0.0 );
typedef long long ll;
#define pii pair<int, int>
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define maximum *max_element
#define minimum *min_element
#define MEMSET(v, x) memset(v, x, sizeof(v))
#define ABS(x) ((x)<0?-(x):(x))
#define white 1
#define grey 2
#define black 3
#define bug cout << "ei porjonto thikase" << endl;
#define fastread ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
int gcd (int a, int b ) {
    a =  abs( a ); b = abs( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;}
int modInverse(int a, int m)
{int m0 = m;int y = 0, x = 1;if (m == 1)return 0;
while (a > 1){int q = a / m;int t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
///====================== khela end1s HERE =====================///
const int maxn = 3005;
int arr[maxn], arr1[maxn];
int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i=1; i<=n; i++){
		scanf("%d %d", &arr[i], &arr1[i]);
	}
	int ans = 0, fromlast = 0;
	for(int i=1; i<=3001; i++){
		int curday = 0;
		for(int j=1; j<=n; j++){
			if(arr[j] == i){
				curday = arr1[j];
			}
		}

		int take = k;
		if(fromlast + curday <= k){
			ans += curday + fromlast;
			fromlast = 0;
		}
		else{
			ans += take;
			int tv = take - fromlast;
			if(tv < 0)tv = 0;
			fromlast = curday - tv;
		}
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define F first
#define S second
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

const int N = 1e6 + 5;
int main()
{
    vector<pair<int,int> > v ;
    int n,k ; cin >> n >> k ;
    for(int i=0 ; i<n ; i++)
    {
        int x,y;
        cin >> x>>y ;
        v.push_back({x,y});
    }
    v.push_back({n,0});
    sort(v.begin() , v.end());
    int cry=0, ans=0 ;
    for(int i=0 ; i<=n ; i++)
    {
        if(v[i].S+cry<k)ans+=v[i].S+cry;
        else
        {
            if(cry<k)
            {
                ans+=cry;
                ans+=k-cry;
                cry=v[i].S-(k-cry);
            }
            else
            {
                ans+=k ;
                cry=v[i].S ;
            }
        }
    }
    cout<<ans ;
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define F first
#define S second
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

const int N = 1e6 + 5;
int main()
{
    vector<int > v ;
    int n,k ; cin >> n >> k ;
    for(int i=1 ; i<3002 ; i++)v.push_back(0);
    for(int i=0 ; i<n ; i++)
    {
        int x,y;
        cin >> x>>y ;
        v[x]=y;
    }
    int cry=0, ans=0 ;
    for(int i=1 ; i<=3001 ; i++)
    {
        if(v[i]+cry<k)ans+=v[i]+cry,cry=0;
        else
        {
            if(cry<k)
            {
                ans+=cry;
                ans+=k-cry;
                cry=v[i]-(k-cry);
            }
            else
            {
                ans+=k ;
                cry=v[i] ;
            }
        }
    }
    cout<<ans ;
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define F first
#define S second
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

const int N = 1e6 + 5;
int main()
{
    vector<int > v ;
    int n,k ; cin >> n >> k ;
    for(int i=1 ; i<3002 ; i++)v.push_back(0);
    for(int i=0 ; i<n ; i++)
    {
        int x,y;
        cin >> x>>y ;
        v[x]=y;
    }
    int cry=0, ans=0 ;
    for(int i=1 ; i<=3001 ; i++)
    {
        if(v[i]+cry<=k)ans+=v[i]+cry,cry=0;
        else
        {
            if(cry<k)
            {
                ans+=cry;
                if(v[i]>=k)ans+=k-cry, cry=abs(v[i]-(k-cry));
                else ans+=v[i],cry=0;
            }
            else
            {
                ans+=k ;
                cry=v[i] ;
            }
        }
    }
    cout<<ans ;
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define F first
#define S second
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

const int N = 1e6 + 5;
int main()
{
    vector<pair<int,int> > v ;
    int n,k ; cin >> n >> k ;
    for(int i=0 ; i<n ; i++)
    {
        int x,y;
        cin >> x>>y ;
        v.push_back({x,y});
    }
    v.push_back({n,0});
    sort(v.begin() , v.end());
    int cry=0, ans=0 ;
    for(int i=0 ; i<=n ; i++)
    {
        if(v[i].S+cry<k)ans+=v[i].S+cry,cry=0;
        else
        {
            if(cry<k)
            {
                ans+=cry;
                ans+=k-cry;
                cry=v[i].S-(k-cry);
            }
            else
            {
                ans+=k ;
                cry=v[i].S ;
            }
        }
    }
    cout<<ans ;
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define F first
#define S second
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

const int N = 1e6 + 5;
int main()
{
    vector<int > v ;
    int n,k ; cin >> n >> k ;
    for(int i=1 ; i<3002 ; i++)v.push_back(0);
    for(int i=0 ; i<n ; i++)
    {
        int x,y;
        cin >> x>>y ;
        v[x]=y;
    }
    int cry=0, ans=0 ;
    for(int i=1 ; i<=3001 ; i++)
    {
        if(v[i]+cry<=k)ans+=v[i]+cry,cry=0;
        else
        {
            if(cry<k)
            {
                ans+=cry;
                ans+=k-cry;
                cry=abs(v[i]-(k-cry));
            }
            else
            {
                ans+=k ;
                cry=v[i] ;
            }
        }
    }
    cout<<ans ;
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define F first
#define S second
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

const int N = 1e6 + 5;
int main()
{
    vector<int > v ;
    int n,k ; cin >> n >> k ;
    for(int i=1 ; i<3002 ; i++)v.push_back(0);
    for(int i=0 ; i<n ; i++)
    {
        int x,y;
        cin >> x>>y ;
        v[x]=y;
    }
    int cry=0, ans=0 ;
    for(int i=1 ; i<=3001 ; i++)
    {
        if(v[i]+cry<=k)ans+=v[i]+cry,cry=0;
        else
        {
            if(cry<k)
            {
                ans+=cry;
                if(v[i]>=(k-cry))ans+=k-cry, cry=abs(v[i]-(k-cry));
                else ans+=v[i],cry=0;
            }
            else
            {
                ans+=k ;
                cry=v[i] ;
            }
        }
    }
    cout<<ans ;
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define F first
#define S second
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

const int N = 1e6 + 5;
int main()
{
    vector<int > v ;
    int n,k ; cin >> n >> k ;
    for(int i=1 ; i<3002 ; i++)v.push_back(0);
    for(int i=0 ; i<n ; i++)
    {
        int x,y;
        cin >> x>>y ;
        v[x]+=y;
    }
    int cry=0, ans=0 ;
    for(int i=1 ; i<=3001 ; i++)
    {
        if(v[i]+cry<=k)ans+=v[i]+cry,cry=0;
        else
        {
            if(cry<k)
            {
                ans+=cry;
                if(v[i]>=(k-cry))ans+=k-cry, cry=abs(v[i]-(k-cry));
                else ans+=v[i],cry=0;
            }
            else
            {
                ans+=k ;
                cry=v[i] ;
            }
        }
    }
    cout<<ans ;
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define F first
#define S second
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

const int N = 1e6 + 5;
int main()
{
    vector<int > v ;
    int n,k ; cin >> n >> k ;
    for(int i=1 ; i<3002 ; i++)v.push_back(0);
    for(int i=0 ; i<n ; i++)
    {
        int x,y;
        cin >> x>>y ;
        v[x]=y;
    }
    int cry=0, ans=0 ;
    for(int i=1 ; i<=3001 ; i++)
    {
        if(v[i]+cry<=k)ans+=v[i]+cry,cry=0;
        else
        {
            if(cry<k)
            {
                ans+=cry;
                ans+=k-cry;
                cry=v[i]-(k-cry);
            }
            else
            {
                ans+=k ;
                cry=v[i] ;
            }
        }
    }
    cout<<ans ;
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int fruits[30003];

int main() {
	int n, v, d, f;

	cin >> n;
	while (n--) {
		cin >> a >> b;
		fruits[a] += b;
	}

	int ans = 0;

	for (int i=1; i < 3002; i++) {
		int m = min(v,x[i-1]);
    	ans += m;
    	if (v>m) {
    		ans += min(v-m,x[i]);
    		x[i] -= min(v-m,x[i]);
    	}
	}

	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int fruits[30003];

int main() {
	int n, v, a, b;

	cin >> n;
	while (n--) {
		cin >> a >> b;
		fruits[a] += b;
	}

	int ans = 0;

	for (int i=1; i < 3002; i++) {
		int m = min(v,x[i-1]);
    	ans += m;
    	if (v>m) {
    		ans += min(v-m,x[i]);
    		x[i] -= min(v-m,x[i]);
    	}
	}

	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int fruits[30003];

int main() {
	int n, v, a, b;

	cin >> n;
	while (n--) {
		cin >> a >> b;
		fruits[a] += b;
	}

	int ans = 0;

	for (int i=1; i < 3002; i++) {
		int m = min(v,fruits[i-1]);
    	ans += m;
    	if (v>m) {
    		ans += min(v-m,fruits[i]);
    		fruits[i] -= min(v-m,fruits[i]);
    	}
	}

	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int fruits[30003];

int main() {
	int n, v, a, b;

	cin >> n >> v;
	while (n--) {
		cin >> a >> b;
		fruits[a] += b;
	}

	int ans = 0;

	for (int i=1; i < 3002; i++) {
		int m = min(v,fruits[i-1]);
    	ans += m;
    	if (v>m) {
    		ans += min(v-m,fruits[i]);
    		fruits[i] -= min(v-m,fruits[i]);
    	}
	}

	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define min(a, b) (a < b ? a : b)

struct Fruit {
	int day;
	int fruits;
};

bool compare(Fruit &f1, Fruit &f2) {
	return f1.day < f2.day;
}

void take(int i, int &v, vector<Fruit> &fruits, int &ans) {
	ans += min(fruits[i].fruits, v);
	// cout << fruits[i].fruits << " " << ans << endl;
	if (v <= fruits[i].fruits) {
		fruits[i].fruits -= v;
		v = 0;
	} else {
		fruits[i].fruits = 0;
		v -= fruits[i].fruits;
	}
}

int main() {
	int n, v;
	vector<Fruit> fruits;
	cin >> n >> v;

	while (n--) {
		Fruit f;
		cin >> f.day >> f.fruits;
		fruits.push_back(f);
	}

	sort(fruits.begin(), fruits.end(), compare);

	int ans = 0;
	int v2 = v;

	take(0, v, fruits, ans);

	for (int i=1; i < fruits.size(); i++) {
		v = v2;
		take(i-1, v, fruits, ans);
		take(i, v, fruits, ans);
	}

	v = v2;
	take(fruits.size() - 1, v, fruits, ans);

	cout << ans << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define min(a, b) (a < b ? a : b)

struct Fruit {
	int day;
	int fruits;
};

bool compare(Fruit &f1, Fruit &f2) {
	return f1.day < f2.day;
}

void take(int i, int &v, vector<Fruit> &fruits, int &ans) {
	if (v <= fruits[i].fruits) {
		fruits[i].fruits -= v;
		ans += v;

		v = 0;
	} else {
		v -= fruits[i].fruits;
		ans += fruits[i].fruits;
		fruits[i].fruits = 0;
	}
}

int main() {
	int n, v;
	vector<Fruit> fruits;
	cin >> n >> v;

	while (n--) {
		Fruit f;
		cin >> f.day >> f.fruits;
		fruits.push_back(f);
	}

	sort(fruits.begin(), fruits.end(), compare);

	int ans = 0;
	int v2 = v;

	take(0, v, fruits, ans);

	for (int i=1; i < fruits.size(); i++) {
		v = v2;
		take(i-1, v, fruits, ans);
		take(i, v, fruits, ans);
	}

	v = v2;
	take(fruits.size() - 1, v, fruits, ans);

	cout << ans << endl;

	return 0;
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , c  = 1 , sum , j ,diff;
pair < int  , int > p[3003];
int main(){
      cin>>n>>m;
      for(int i = 0 ; i < n ; i++){
            cin>>p[i].first>>p[i].second;
      }
      sort(p,p+n);
      for(int i = 0 ; i  < n ; i++){
         if(c<=p[i].first+1){
                  while(p[i].second>0){
                            if(i==n-1) break;
                            j = i+1;
                         sum+=min(p[i].second,m);
                        if(p[i].second>=m){
                              p[i].second -= m;
                        }
                        else{
                              diff=m-p[i].second;
                                   if(p[j].second>=diff){
                                    p[j].second -= diff;
                                    sum+=diff;
                                    diff = 0;
                                   }
                                   else{
                                         sum += p[j].second;
                                         p[j].second = 0 ;
                                         diff=0;
                                   }
                               p[i].second = 0;
                              }
                         c++;
                         if(c>p[i].first+1) break;
            }
         }

      }
       cout<<sum<<endl;

}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , c  = 1 , sum , j;
pair < int  , int > p[30003];
int main(){
      cin>>n>>m;
      for(int i = 0 ; i < n ; i++){
            cin>>p[i].first>>p[i].second;
      }
      sort(p,p+n);
      cout<<endl;
      for(int i = 0 ; i  < n ; i++){
         if(c<=p[i].first+1){
                  while(p[i].second>0){
                              j=i+1;
                         if(c>p[i].first+1) break;
                         sum+=min(p[i].second,m);
                        if(p[i].second>=m){
                              p[i].second -= m;
                        }
                        else{
                              while(p[j].second>0){
                                    if(p[j].second>m){
                                          p[j].second -=m;
                                          sum+=m;
                                          break;
                                    }
                                    else{
                                          sum += p[j].second;
                                          p[j].second = 0;
                                          j++;
                                    }
                              }
                        }
                         c++;

            }
         }

      }
       cout<<sum<<endl;

}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , c  = 1 , sum , j ,diff;
pair < int  , int > p[3003];
int main(){
      cin>>n>>m;
      for(int i = 0 ; i < n ; i++){
            cin>>p[i].first>>p[i].second;
      }
      sort(p,p+n);
      for(int i = 0 ; i  < n ; i++){
         if(c<=p[i].first+1){
                  while(p[i].second>0){
                            //if(i==n-1) break;
                            j = i+1;
                         sum+=min(p[i].second,m);
                        if(p[i].second>=m){
                              p[i].second -= m;
                        }
                        else{
                              diff=m-p[i].second;
                                   if(p[j].second>=diff){
                                    p[j].second -= diff;
                                    sum+=diff;
                                    diff = 0;
                                   }
                                   else{
                                         sum += p[j].second;
                                         p[j].second = 0 ;
                                         diff=0;
                                   }
                               p[i].second = 0;
                              }
                         c++;
                         if(c>p[i].first+1) break;
            }
         }

      }
       cout<<sum<<endl;

}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , c  = 1 , sum , j;
pair < int  , int > p[30003];
int main(){
      cin>>n>>m;
      for(int i = 0 ; i < n ; i++){
            cin>>p[i].first>>p[i].second;
      }
      sort(p,p+n);
      cout<<endl;
      for(int i = 0 ; i  < n ; i++){
         if(c<=p[i].first+1){
            // if(p[i].second<m){
            //       while(p[j].second<m){
            //             sum+=p[j].second;
            //             j++;
            //             p[j].second = 0;
            //       }
            //       sum+=p[i].second;
            //       p[i].second= 0;
            //       i = j ;
            //       j = 0;
            // }
            // else{
                  while(p[i].second>0){
                         if(c>p[i].first+1) break;
                         sum+=min(p[i].second,m);
                         p[i].second-=m;
                         c++;

            }
         }

      }
       cout<<sum<<endl;

}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , c  = 1 , sum , j ,diff;
pair < int  , int > p[30003];
int main(){
      cin>>n>>m;
      for(int i = 0 ; i < n ; i++){
            cin>>p[i].first>>p[i].second;
      }
      sort(p,p+n);
      cout<<endl;
      for(int i = 0 ; i  < n ; i++){
         if(c<=p[i].first+1){
                  while(p[i].second>0){
                            if(i!=n-1)  j=i+1;
                        if(c>p[i].first+1) break;
                         sum+=min(p[i].second,m);
                        if(p[i].second>=m){
                              p[i].second -= m;
                        }
                        else{
                              diff=m-p[i].second;
                              while(diff>0){
                                   if(i==n-1) break;
                                   if(p[j].second>=diff){
                                    p[j].second -= diff;
                                    sum+=diff;
                                    diff = 0;
                                   }
                                   else{
                                         diff-=p[j].second;
                                         sum+=diff;
                                         j++;
                                   }
                              }
                              p[i].second = 0;
                        }
                         c++;

            }
         }

      }
       cout<<sum<<endl;

}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
//couldn't figure this one myself :(
using namespace std;
int a[100000];
int n , v , x , y , ans , c;
int main(){
      cin>>n>>v;
      for(int i = 0 ; i < n ; i++){
            cin>>x>>y;
            a[x]+=y;
      }
      x = 0 ; y = 0 ;
      for(int i = 1  ; i <=3003 ; i++){
            x = a[i];
            ans+=min(y,v);
            c = v - min(y,v);
            if(x<=c){
                  ans+=x;
                  y=0;
            }
            else{
                  ans+=c;
                  y = x - c;
            }
      }
      cout<<ans<<endl;
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , c  = 1 , sum , j ,diff;
pair < int  , int > p[3003];
int main(){
      cin>>n>>m;
      for(int i = 0 ; i < n ; i++){
            cin>>p[i].first>>p[i].second;
      }
      sort(p,p+n);
      for(int i = 0 ; i  < n ; i++){
         if(c<=p[i].first+1){
                  while(p[i].second>0){
                            //if(i==n-1) break;
                            j = i+1;
                         sum+=min(p[i].second,m);
                        if(p[i].second>=m){
                              p[i].second -= m;
                        }
                        else{
                              diff=m-p[i].second;
                                   if(p[j].second>diff){
                                    p[j].second -= diff;
                                    sum+=diff;
                                    diff = 0;
                                   }
                                   else{
                                         sum += p[j].second;
                                         p[j].second = 0 ;
                                         diff=0;
                                   }
                               p[i].second = 0;
                              }
                         c++;
                         if(c>p[i].first+1) break;
            }
         }

      }
       cout<<sum<<endl;

}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , c  = 1 , sum , j ,diff;
pair < int  , int > p[3003];
int main(){
      cin>>n>>m;
      for(int i = 0 ; i < n ; i++){
            cin>>p[i].first>>p[i].second;
      }
      sort(p,p+n);
      for(int i = 0 ; i  < n ; i++){
         if(c<=p[i].first+1){
                c++;
                         if(c>p[i].first+1) break;
                  while(p[i].second>0){
                            //if(i==n-1) break;
                            j = i+1;
                         sum+=min(p[i].second,m);
                        if(p[i].second>=m){
                              p[i].second -= m;
                        }
                        else{
                              diff=m-p[i].second;
                                   if(p[j].second>diff){
                                    p[j].second -= diff;
                                    sum+=diff;
                                    diff = 0;
                                   }
                                   else{
                                         sum += p[j].second;
                                         p[j].second = 0 ;
                                         diff=0;
                                   }
                               p[i].second = 0;
                              }
            }
         }

      }
       cout<<sum<<endl;

}