#include<stdio.h>
#include<stdlib.h>
long n,v,d[3005]={0},m=0;
int main()
{
	long i,a,b,l0=0,l1=0,ans=0,vv;
	scanf("%ld %ld",&n,&v);
	for (i=1;i<=n;i++)
	{
		scanf("%ld %ld",&a,&b);
		d[a]+=b;
		if (a>m) m=a;
	}
	m++;
	for (i=1;i<=m;i++)
	{
		l0=l1;
		l1=d[i];
		if (l0>=v) ans+=v;
		else
		{
			ans+=l0;
			vv=v-l0;
			if (vv>=l1)
			{
				l1=0;
				ans+=l1;
			}
			else
			{
				l1-=vv;
				ans+=vv;
			}
		}
	}
	printf("%ld",ans);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int max(int a, int b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

int min(int a, int b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}

int main() {
  int trees;
  int capacity;
  int i, j, k;
  int freq_day[3002] = {0};
  int sum = 0;

  scanf("%d", &trees);
  scanf("%d", &capacity);

  for (i = 0; i < trees; i++) {
    scanf("%d", &j);
    scanf("%d", &k);
    freq_day[j] += k;
  }

  for (i = 1; i < 3002; i++) {
    sum += min(freq_day[i] + freq_day[i - 1], capacity);
    freq_day[i] = max(0, freq_day[i] - abs(capacity - freq_day[i - 1]));
  }

  printf("%d\n", sum);
  return 0;
}


#include <stdio.h>
#include <stdlib.h>

int max(int a, int b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

int min(int a, int b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}

int main() {
  int trees;
  int capacity;
  int i, j, k;
  int freq_day[3002] = {0};
  int sum = 0;

  scanf("%d", &trees);
  scanf("%d", &capacity);

  for (i = 0; i < trees; i++) {
    scanf("%d", &j);
    scanf("%d", &k);
    freq_day[j] += k;
  }

  for (i = 1; i < 3002; i++) {
    sum += min(freq_day[i] + freq_day[i - 1], capacity);
    freq_day[i] = max(0, freq_day[i] - max(0, capacity - freq_day[i - 1]));
  }

  printf("%d\n", sum);
  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define SET(a,b) memset(a,b,sizeof(a))
#define scan(n) scanf("%d",&n)
#define print(n) printf("%d\n",n)
#define scanl(n) scanf("%lld",&n)
#define printl(n) printf("%lld\n",n)

//stacks
/*void push(int n,int ar[],int i)
{
        ar[i]=n;
        i++;
}
void pop(int ar[],int i)
{
        if(i>0)
        {
                ar[i-1]=0;
                i--;
        }
}*/

//queues
/*void qpush(int ar[],int val,int head,int tail,int range)
{
        if(head==tail)
        {
                ar[head]=val;
                if(tail+1==range)
                        tail=0;
                else
                        tail++;
        }
        else
        {
                ar[tail]=val;
                if(tail+1==range)
                        tail=0;
                else
                        tail++;
        }
        if(tail==head)
        {
                if(head+1==range)
                        head=0;
                else
                        head++;
        }
}

void qpop(int head,int tail,int range)
{
        if(head+1==range)
                head=0;
        else
                head++;
}*/

//pow
/*int fun(int a,int b,int m)
{
        if(b==0)
                return 1;
        int d,x;
        d=fun(a,b/2,m);
        x=(d*d)%m;
        if(b%2==0)
                return x;
        else
                return (x*a%m)%m;
}
*/
//bst
/*typedef struct tree
{
        int val;
        struct tree *l;
        struct tree *r;
}node;
//node *head;
node *insert(int x,node *root)
{
        if(root==NULL)
        {
                root=(node *)malloc(sizeof(node));
                root->val=x;
        }
        else
        {
                if(x<=root->val)
                {
                        if(root->l==NULL)
                        {
                                root->l=(node *)malloc(sizeof(node));
                                root->l->val=x;
                        }
                        else
                                root->l=insert(x,root->l);
                }
                else
                {
                        if(root->r==NULL)
                        {
                                root->r=(node *)malloc(sizeof(node));
                                root->r->val=x;
                        }
                        else
                        {
                                root->r=insert(x,root->r);
                        }
                }
        }
        return root;
}
node *find(int x,node *root)
{
        if(root==NULL)
        {
                return 0;
        }
        else
        {
                if(x==root->val)
                        return root;
                else if(x<root->val)
                {
                        if(root->l==NULL)
                        {
                                return 0;
                        }
                        else
                        {
                                find(x,root->l);
                        }
                }
                else
                {
                        if(root->r==NULL)
                        {
                                return 0;
                        }
                        else
                        {
                                find(x,root->r);
                        }
                }
        }
}

void inorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        if(root->l==NULL)
        {
                printf("%d",root->val);
                if(root->r==NULL)
                        return;
                else
                        inorder(root->r);
        }
        else
        {
                inorder(root->l);
                printf("%d",root->val);
                if(root->r==NULL)
                        return;
                else
                        inorder(root->r);
        }
}
void preorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        else
        {
                printf("%d",root->val);
                preorder(root->l);
                preorder(root->r);
        }
}

void postorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        else
        {
                postorder(root->l);
                postorder(root->r);
                printf("%d",root->val);
        }
}
*/
//adjacency list
/*typedef struct ll
{
        int val;
        struct ll *next;
}nd;

//n *ar[100001];
void insert(int a,int b)
{
        if(ar[a]==NULL)
        {
                ar[a]=(nd *)malloc(sizeof(nd));
                ar[a]->val=b;
                ar[a]->next=NULL;
        }
        else
        {
                nd *temp=(nd *)malloc(sizeof(nd)),*t;
                temp->val=b;
                temp->next=ar[a];
                ar[a]=temp;
        }
}

//dfs
//int state[100001];
void dfs(int a)
{
        state[a]=1;
        count++;
        nd *temp=ar[a];
        while(temp!=NULL)
        {
                if(state[temp->val]!=1)
                        dfs(temp->val);
                temp=temp->next;
        }
        return;
}*/

//dijkstra + heaps
/*typedef struct ll2
{
        int val;
        int weight;
        struct ll2 *next;
}nde;
*/
//nde *ar[500005];
//int state[500005];

/*void insert(int a,int b,int w)//insert to adjacency list
  {
  if(ar[a]==NULL)
  {
  ar[a]=(node *)malloc(sizeof(node));
  ar[a]->val=b;
  ar[a]->weight=w;
  ar[a]->next=NULL;
  }
  else
  {
  node *temp=(node *)malloc(sizeof(node)),*t;
  temp->val=b;
  temp->weight=w;
  temp->next=ar[a];
  ar[a]=temp;
  }
  }*/

//int pt[500005],d[500005];
//int heap[500005][2];
//int ptr;
/*void decpty(int val,int pos)//decrease priority
{
        heap[pos][0]=val;
        int x=pos;
        while(x>0)
        {
                if(heap[x][0]>=heap[x/2][0])
                        break;
                else
                {
                        pt[heap[x][1]]=x/2;
                        pt[heap[x/2][1]]=x;
                        int temp=heap[x][0],t2=heap[x][1];
                        heap[x][0]=heap[x/2][0];
                        heap[x][1]=heap[x/2][1];
                        heap[x/2][0]=temp;
                        heap[x/2][1]=t2;
                        x=x/2;
                }
        }
}

void hinsert(int val,int val2)//insert to heap
{
        heap[ptr][0]=val;
        heap[ptr][1]=val2;
        pt[val2]=ptr;
        int x=ptr;
        ptr++;
        while(x>0)
        {
                if(heap[x][0]>=heap[x/2][0])
                        break;
                else
                {
                        pt[heap[x][1]]=x/2;
                        pt[heap[x/2][1]]=x;
                        int temp=heap[x][0],t2=heap[x][1];
                        heap[x][0]=heap[x/2][0];
                        heap[x][1]=heap[x/2][1];
                        heap[x/2][0]=temp;
                        heap[x/2][1]=t2;
                        x=x/2;
                }
        }
}

int hdeletemin()//delete min elem from heap
{
        int ret;
        ret=heap[1][1];
        pt[heap[1][1]]=-1;
        pt[heap[ptr-1][1]]=1;
        heap[1][0]=heap[ptr-1][0];
        heap[1][1]=heap[ptr-1][1];
        ptr--;
        int x=1;
        while(x<ptr)
        {
                if(2*x+1>=ptr)
                {
                        if(2*x<ptr)
                        {
                                if(heap[2*x][0]<heap[x][0])
                                {
                                        pt[heap[x][1]]=2*x;
                                        pt[heap[2*x][1]]=x;
                                        int temp=heap[x][0];
                                        int temp2=heap[x][1];
                                        heap[x][0]=heap[2*x][0];
                                        heap[x][1]=heap[2*x][1];
                                        heap[2*x][0]=temp;
                                        heap[2*x][1]=temp2;
                                        x=2*x;
                                }
                                else
                                        break;
                        }
                        else
                                break;
                }
                else if(heap[x][0]<=heap[2*x][0] && heap[x][0]<=heap[2*x+1][0])
                        break;
                else
                {
                        if(heap[2*x][0]<=heap[2*x+1][0])
                        {
                                pt[heap[x][1]]=2*x;
                                pt[heap[2*x][1]]=x;
                                int temp=heap[x][0];
                                int temp2=heap[x][1];
                                heap[x][0]=heap[2*x][0];
                                heap[x][1]=heap[2*x][1];
                                heap[2*x][0]=temp;
                                heap[2*x][1]=temp2;
                                x=2*x;
                        }
                        else
                        {
                                pt[heap[x][1]]=2*x+1;
                                pt[heap[2*x+1][1]]=x;
                                int temp=heap[x][0];
                                int temp2=heap[x][1];
                                heap[x][0]=heap[2*x+1][0];
                                heap[x][1]=heap[2*x+1][1];
                                heap[2*x+1][0]=temp;
                                heap[2*x+1][1]=temp2;
                                x=2*x+1;
                        }
                }
        }
        return ret;
}

void dikstra(int u,int v)
{
        while(ptr!=1)
        {
                int v=hdeletemin();
                node *temp=ar[v];
                while(temp!=NULL)
                {
                        int w=temp->val;
                        if(d[v]+temp->weight < d[w])
                        {
                                d[w]=d[v]+temp->weight;
                                decpty(d[w],pt[w]);
                        }
                        temp=temp->next;
                }
        }
}*/

/*int main()
  {
  int n,m,u,v,w,i;
  scanf("%d%d",&n,&m);
  for(i=0;i<=n;i++)
  state[i]=0;
  while(m--)
  {
  scanf("%d%d%d",&u,&v,&w);
  insert(u,v,w);
  }
  scanf("%d%d",&u,&v);
  ptr=1;
  hinsert(0,u);
  d[u]=0;
  for(i=1;i<=n;i++)
  {
  if(i!=u)
  {
  hinsert(1000000000,i);
  d[i]=1000000000;
  }
  }
  dikstra(u,v);
  if(d[v]==1000000000)
  printf("NO\n");
  else
  printf("%d\n",d[v]);
  return 0;
  }*/

//kruskal + dsu

//int dsu[N];
/*int find(int x)
{
        if(dsu[x]==x)return x;
        return dsu[x] = find(dsu[x]);
}

void Union(int a,int b)
{
        if(a==b)
                return;
        dsu[a] = b;
}

typedef struct edge
{
        int u,v;
        int weight;
}edge;
*/
//edge e[N];
/*int cmp(const void *a,const void *b)
  {
  return ((edge*)a)->weight - ((edge*)b)->weight;
  }*/
/*int main()
  {
  int i;
  int n,m;
  scanf("%d %d\n",&n,&m);
  for(i=0;i<m;i++)
  scanf("%d %d %d",&e[i].u,&e[i].v,&e[i].weight);
  for(i=1;i<=n;i++)
  dsu[i]=i;
  qsort(e,m,sizeof(edge),cmp);
  long long int sum=0;
  for(i=0;i<m;i++)
  {
  int a,b;
  if((a=find(e[i].u))!=(b=find(e[i].v)))
  {
  sum+=e[i].weight;
  Union(a,b);
  }
  }
  printf("%lld\n",sum);
  return 0;
  }*/

//qsort

/*int cmpfunc(const void *a,const void *b)
{
        return (*(int *)a - *(int *)b);
}*/
//qsort(ar,n,sizeof(int),cmpfunc);

//-------------------------------------------------------------------------------------------------------------------------------------

int main()
{
        int n,v,a[3001],pre,val1,val2,ans=0,i;
        scan(n);
        scan(v);
        pre=0;
        int max=0;
        for(i=0;i<n;i++)
        {
                scan(val1);
                scan(val2);
                a[val1]+=val2;
                if(val1>max)
                        max=val1;
        }
        for(i=1;i<=max+1;i++)
        {
                if(pre<=v)
                {
                        ans+=pre;
                        int x=v-pre;
                        if(a[i]<=x)
                        {
                                ans+=a[i];
                                pre=0;
                        }
                        else
                        {
                                ans+=x;
                                pre=a[i]-x;
                        }

                }
                else
                {
                        ans+=v;
                        pre=a[i];
                }
        }
        print(ans);
        return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define SET(a,b) memset(a,b,sizeof(a))
#define scan(n) scanf("%d",&n)
#define print(n) printf("%d\n",n)
#define scanl(n) scanf("%lld",&n)
#define printl(n) printf("%lld\n",n)

//stacks
/*void push(int n,int ar[],int i)
{
        ar[i]=n;
        i++;
}
void pop(int ar[],int i)
{
        if(i>0)
        {
                ar[i-1]=0;
                i--;
        }
}*/

//queues
/*void qpush(int ar[],int val,int head,int tail,int range)
{
        if(head==tail)
        {
                ar[head]=val;
                if(tail+1==range)
                        tail=0;
                else
                        tail++;
        }
        else
        {
                ar[tail]=val;
                if(tail+1==range)
                        tail=0;
                else
                        tail++;
        }
        if(tail==head)
        {
                if(head+1==range)
                        head=0;
                else
                        head++;
        }
}

void qpop(int head,int tail,int range)
{
        if(head+1==range)
                head=0;
        else
                head++;
}*/

//pow
/*int fun(int a,int b,int m)
{
        if(b==0)
                return 1;
        int d,x;
        d=fun(a,b/2,m);
        x=(d*d)%m;
        if(b%2==0)
                return x;
        else
                return (x*a%m)%m;
}
*/
//bst
/*typedef struct tree
{
        int val;
        struct tree *l;
        struct tree *r;
}node;
//node *head;
node *insert(int x,node *root)
{
        if(root==NULL)
        {
                root=(node *)malloc(sizeof(node));
                root->val=x;
        }
        else
        {
                if(x<=root->val)
                {
                        if(root->l==NULL)
                        {
                                root->l=(node *)malloc(sizeof(node));
                                root->l->val=x;
                        }
                        else
                                root->l=insert(x,root->l);
                }
                else
                {
                        if(root->r==NULL)
                        {
                                root->r=(node *)malloc(sizeof(node));
                                root->r->val=x;
                        }
                        else
                        {
                                root->r=insert(x,root->r);
                        }
                }
        }
        return root;
}
node *find(int x,node *root)
{
        if(root==NULL)
        {
                return 0;
        }
        else
        {
                if(x==root->val)
                        return root;
                else if(x<root->val)
                {
                        if(root->l==NULL)
                        {
                                return 0;
                        }
                        else
                        {
                                find(x,root->l);
                        }
                }
                else
                {
                        if(root->r==NULL)
                        {
                                return 0;
                        }
                        else
                        {
                                find(x,root->r);
                        }
                }
        }
}

void inorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        if(root->l==NULL)
        {
                printf("%d",root->val);
                if(root->r==NULL)
                        return;
                else
                        inorder(root->r);
        }
        else
        {
                inorder(root->l);
                printf("%d",root->val);
                if(root->r==NULL)
                        return;
                else
                        inorder(root->r);
        }
}
void preorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        else
        {
                printf("%d",root->val);
                preorder(root->l);
                preorder(root->r);
        }
}

void postorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        else
        {
                postorder(root->l);
                postorder(root->r);
                printf("%d",root->val);
        }
}
*/
//adjacency list
/*typedef struct ll
{
        int val;
        struct ll *next;
}nd;

//n *ar[100001];
void insert(int a,int b)
{
        if(ar[a]==NULL)
        {
                ar[a]=(nd *)malloc(sizeof(nd));
                ar[a]->val=b;
                ar[a]->next=NULL;
        }
        else
        {
                nd *temp=(nd *)malloc(sizeof(nd)),*t;
                temp->val=b;
                temp->next=ar[a];
                ar[a]=temp;
        }
}

//dfs
//int state[100001];
void dfs(int a)
{
        state[a]=1;
        count++;
        nd *temp=ar[a];
        while(temp!=NULL)
        {
                if(state[temp->val]!=1)
                        dfs(temp->val);
                temp=temp->next;
        }
        return;
}*/

//dijkstra + heaps
/*typedef struct ll2
{
        int val;
        int weight;
        struct ll2 *next;
}nde;
*/
//nde *ar[500005];
//int state[500005];

/*void insert(int a,int b,int w)//insert to adjacency list
  {
  if(ar[a]==NULL)
  {
  ar[a]=(node *)malloc(sizeof(node));
  ar[a]->val=b;
  ar[a]->weight=w;
  ar[a]->next=NULL;
  }
  else
  {
  node *temp=(node *)malloc(sizeof(node)),*t;
  temp->val=b;
  temp->weight=w;
  temp->next=ar[a];
  ar[a]=temp;
  }
  }*/

//int pt[500005],d[500005];
//int heap[500005][2];
//int ptr;
/*void decpty(int val,int pos)//decrease priority
{
        heap[pos][0]=val;
        int x=pos;
        while(x>0)
        {
                if(heap[x][0]>=heap[x/2][0])
                        break;
                else
                {
                        pt[heap[x][1]]=x/2;
                        pt[heap[x/2][1]]=x;
                        int temp=heap[x][0],t2=heap[x][1];
                        heap[x][0]=heap[x/2][0];
                        heap[x][1]=heap[x/2][1];
                        heap[x/2][0]=temp;
                        heap[x/2][1]=t2;
                        x=x/2;
                }
        }
}

void hinsert(int val,int val2)//insert to heap
{
        heap[ptr][0]=val;
        heap[ptr][1]=val2;
        pt[val2]=ptr;
        int x=ptr;
        ptr++;
        while(x>0)
        {
                if(heap[x][0]>=heap[x/2][0])
                        break;
                else
                {
                        pt[heap[x][1]]=x/2;
                        pt[heap[x/2][1]]=x;
                        int temp=heap[x][0],t2=heap[x][1];
                        heap[x][0]=heap[x/2][0];
                        heap[x][1]=heap[x/2][1];
                        heap[x/2][0]=temp;
                        heap[x/2][1]=t2;
                        x=x/2;
                }
        }
}

int hdeletemin()//delete min elem from heap
{
        int ret;
        ret=heap[1][1];
        pt[heap[1][1]]=-1;
        pt[heap[ptr-1][1]]=1;
        heap[1][0]=heap[ptr-1][0];
        heap[1][1]=heap[ptr-1][1];
        ptr--;
        int x=1;
        while(x<ptr)
        {
                if(2*x+1>=ptr)
                {
                        if(2*x<ptr)
                        {
                                if(heap[2*x][0]<heap[x][0])
                                {
                                        pt[heap[x][1]]=2*x;
                                        pt[heap[2*x][1]]=x;
                                        int temp=heap[x][0];
                                        int temp2=heap[x][1];
                                        heap[x][0]=heap[2*x][0];
                                        heap[x][1]=heap[2*x][1];
                                        heap[2*x][0]=temp;
                                        heap[2*x][1]=temp2;
                                        x=2*x;
                                }
                                else
                                        break;
                        }
                        else
                                break;
                }
                else if(heap[x][0]<=heap[2*x][0] && heap[x][0]<=heap[2*x+1][0])
                        break;
                else
                {
                        if(heap[2*x][0]<=heap[2*x+1][0])
                        {
                                pt[heap[x][1]]=2*x;
                                pt[heap[2*x][1]]=x;
                                int temp=heap[x][0];
                                int temp2=heap[x][1];
                                heap[x][0]=heap[2*x][0];
                                heap[x][1]=heap[2*x][1];
                                heap[2*x][0]=temp;
                                heap[2*x][1]=temp2;
                                x=2*x;
                        }
                        else
                        {
                                pt[heap[x][1]]=2*x+1;
                                pt[heap[2*x+1][1]]=x;
                                int temp=heap[x][0];
                                int temp2=heap[x][1];
                                heap[x][0]=heap[2*x+1][0];
                                heap[x][1]=heap[2*x+1][1];
                                heap[2*x+1][0]=temp;
                                heap[2*x+1][1]=temp2;
                                x=2*x+1;
                        }
                }
        }
        return ret;
}

void dikstra(int u,int v)
{
        while(ptr!=1)
        {
                int v=hdeletemin();
                node *temp=ar[v];
                while(temp!=NULL)
                {
                        int w=temp->val;
                        if(d[v]+temp->weight < d[w])
                        {
                                d[w]=d[v]+temp->weight;
                                decpty(d[w],pt[w]);
                        }
                        temp=temp->next;
                }
        }
}*/

/*int main()
  {
  int n,m,u,v,w,i;
  scanf("%d%d",&n,&m);
  for(i=0;i<=n;i++)
  state[i]=0;
  while(m--)
  {
  scanf("%d%d%d",&u,&v,&w);
  insert(u,v,w);
  }
  scanf("%d%d",&u,&v);
  ptr=1;
  hinsert(0,u);
  d[u]=0;
  for(i=1;i<=n;i++)
  {
  if(i!=u)
  {
  hinsert(1000000000,i);
  d[i]=1000000000;
  }
  }
  dikstra(u,v);
  if(d[v]==1000000000)
  printf("NO\n");
  else
  printf("%d\n",d[v]);
  return 0;
  }*/

//kruskal + dsu

//int dsu[N];
/*int find(int x)
{
        if(dsu[x]==x)return x;
        return dsu[x] = find(dsu[x]);
}

void Union(int a,int b)
{
        if(a==b)
                return;
        dsu[a] = b;
}

typedef struct edge
{
        int u,v;
        int weight;
}edge;
*/
//edge e[N];
/*int cmp(const void *a,const void *b)
  {
  return ((edge*)a)->weight - ((edge*)b)->weight;
  }*/
/*int main()
  {
  int i;
  int n,m;
  scanf("%d %d\n",&n,&m);
  for(i=0;i<m;i++)
  scanf("%d %d %d",&e[i].u,&e[i].v,&e[i].weight);
  for(i=1;i<=n;i++)
  dsu[i]=i;
  qsort(e,m,sizeof(edge),cmp);
  long long int sum=0;
  for(i=0;i<m;i++)
  {
  int a,b;
  if((a=find(e[i].u))!=(b=find(e[i].v)))
  {
  sum+=e[i].weight;
  Union(a,b);
  }
  }
  printf("%lld\n",sum);
  return 0;
  }*/

//qsort

/*int cmpfunc(const void *a,const void *b)
{
        return (*(int *)a - *(int *)b);
}*/
//qsort(ar,n,sizeof(int),cmpfunc);

//-------------------------------------------------------------------------------------------------------------------------------------

int main()
{
        int n,v,a[3002],pre,val1,val2,ans=0,i;
        scan(n);
        scan(v);
        pre=0;
        int max=0;
        for(i=0;i<3002;i++)
                a[i]=0;
        for(i=0;i<n;i++)
        {
                scan(val1);
                scan(val2);
                a[val1]+=val2;
                if(val1>max)
                        max=val1;
        }
        for(i=1;i<=max+1;i++)
        {
                if(pre<=v)
                {
                        ans+=pre;
                        int x=v-pre;
                        if(a[i]<=x)
                        {
                                ans+=a[i];
                                pre=0;
                        }
                        else
                        {
                                ans+=x;
                                pre=a[i]-x;
                        }

                }
                else
                {
                        ans+=v;
                        pre=a[i];
                }
        }
        print(ans);
        return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define SET(a,b) memset(a,b,sizeof(a))
#define scan(n) scanf("%d",&n)
#define print(n) printf("%d\n",n)
#define scanl(n) scanf("%lld",&n)
#define printl(n) printf("%lld\n",n)

//stacks
/*void push(int n,int ar[],int i)
{
        ar[i]=n;
        i++;
}
void pop(int ar[],int i)
{
        if(i>0)
        {
                ar[i-1]=0;
                i--;
        }
}*/

//queues
/*void qpush(int ar[],int val,int head,int tail,int range)
{
        if(head==tail)
        {
                ar[head]=val;
                if(tail+1==range)
                        tail=0;
                else
                        tail++;
        }
        else
        {
                ar[tail]=val;
                if(tail+1==range)
                        tail=0;
                else
                        tail++;
        }
        if(tail==head)
        {
                if(head+1==range)
                        head=0;
                else
                        head++;
        }
}

void qpop(int head,int tail,int range)
{
        if(head+1==range)
                head=0;
        else
                head++;
}*/

//pow
/*int fun(int a,int b,int m)
{
        if(b==0)
                return 1;
        int d,x;
        d=fun(a,b/2,m);
        x=(d*d)%m;
        if(b%2==0)
                return x;
        else
                return (x*a%m)%m;
}
*/
//bst
/*typedef struct tree
{
        int val;
        struct tree *l;
        struct tree *r;
}node;
//node *head;
node *insert(int x,node *root)
{
        if(root==NULL)
        {
                root=(node *)malloc(sizeof(node));
                root->val=x;
        }
        else
        {
                if(x<=root->val)
                {
                        if(root->l==NULL)
                        {
                                root->l=(node *)malloc(sizeof(node));
                                root->l->val=x;
                        }
                        else
                                root->l=insert(x,root->l);
                }
                else
                {
                        if(root->r==NULL)
                        {
                                root->r=(node *)malloc(sizeof(node));
                                root->r->val=x;
                        }
                        else
                        {
                                root->r=insert(x,root->r);
                        }
                }
        }
        return root;
}
node *find(int x,node *root)
{
        if(root==NULL)
        {
                return 0;
        }
        else
        {
                if(x==root->val)
                        return root;
                else if(x<root->val)
                {
                        if(root->l==NULL)
                        {
                                return 0;
                        }
                        else
                        {
                                find(x,root->l);
                        }
                }
                else
                {
                        if(root->r==NULL)
                        {
                                return 0;
                        }
                        else
                        {
                                find(x,root->r);
                        }
                }
        }
}

void inorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        if(root->l==NULL)
        {
                printf("%d",root->val);
                if(root->r==NULL)
                        return;
                else
                        inorder(root->r);
        }
        else
        {
                inorder(root->l);
                printf("%d",root->val);
                if(root->r==NULL)
                        return;
                else
                        inorder(root->r);
        }
}
void preorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        else
        {
                printf("%d",root->val);
                preorder(root->l);
                preorder(root->r);
        }
}

void postorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        else
        {
                postorder(root->l);
                postorder(root->r);
                printf("%d",root->val);
        }
}
*/
//adjacency list
/*typedef struct ll
{
        int val;
        struct ll *next;
}nd;

//n *ar[100001];
void insert(int a,int b)
{
        if(ar[a]==NULL)
        {
                ar[a]=(nd *)malloc(sizeof(nd));
                ar[a]->val=b;
                ar[a]->next=NULL;
        }
        else
        {
                nd *temp=(nd *)malloc(sizeof(nd)),*t;
                temp->val=b;
                temp->next=ar[a];
                ar[a]=temp;
        }
}

//dfs
//int state[100001];
void dfs(int a)
{
        state[a]=1;
        count++;
        nd *temp=ar[a];
        while(temp!=NULL)
        {
                if(state[temp->val]!=1)
                        dfs(temp->val);
                temp=temp->next;
        }
        return;
}*/

//dijkstra + heaps
/*typedef struct ll2
{
        int val;
        int weight;
        struct ll2 *next;
}nde;
*/
//nde *ar[500005];
//int state[500005];

/*void insert(int a,int b,int w)//insert to adjacency list
  {
  if(ar[a]==NULL)
  {
  ar[a]=(node *)malloc(sizeof(node));
  ar[a]->val=b;
  ar[a]->weight=w;
  ar[a]->next=NULL;
  }
  else
  {
  node *temp=(node *)malloc(sizeof(node)),*t;
  temp->val=b;
  temp->weight=w;
  temp->next=ar[a];
  ar[a]=temp;
  }
  }*/

//int pt[500005],d[500005];
//int heap[500005][2];
//int ptr;
/*void decpty(int val,int pos)//decrease priority
{
        heap[pos][0]=val;
        int x=pos;
        while(x>0)
        {
                if(heap[x][0]>=heap[x/2][0])
                        break;
                else
                {
                        pt[heap[x][1]]=x/2;
                        pt[heap[x/2][1]]=x;
                        int temp=heap[x][0],t2=heap[x][1];
                        heap[x][0]=heap[x/2][0];
                        heap[x][1]=heap[x/2][1];
                        heap[x/2][0]=temp;
                        heap[x/2][1]=t2;
                        x=x/2;
                }
        }
}

void hinsert(int val,int val2)//insert to heap
{
        heap[ptr][0]=val;
        heap[ptr][1]=val2;
        pt[val2]=ptr;
        int x=ptr;
        ptr++;
        while(x>0)
        {
                if(heap[x][0]>=heap[x/2][0])
                        break;
                else
                {
                        pt[heap[x][1]]=x/2;
                        pt[heap[x/2][1]]=x;
                        int temp=heap[x][0],t2=heap[x][1];
                        heap[x][0]=heap[x/2][0];
                        heap[x][1]=heap[x/2][1];
                        heap[x/2][0]=temp;
                        heap[x/2][1]=t2;
                        x=x/2;
                }
        }
}

int hdeletemin()//delete min elem from heap
{
        int ret;
        ret=heap[1][1];
        pt[heap[1][1]]=-1;
        pt[heap[ptr-1][1]]=1;
        heap[1][0]=heap[ptr-1][0];
        heap[1][1]=heap[ptr-1][1];
        ptr--;
        int x=1;
        while(x<ptr)
        {
                if(2*x+1>=ptr)
                {
                        if(2*x<ptr)
                        {
                                if(heap[2*x][0]<heap[x][0])
                                {
                                        pt[heap[x][1]]=2*x;
                                        pt[heap[2*x][1]]=x;
                                        int temp=heap[x][0];
                                        int temp2=heap[x][1];
                                        heap[x][0]=heap[2*x][0];
                                        heap[x][1]=heap[2*x][1];
                                        heap[2*x][0]=temp;
                                        heap[2*x][1]=temp2;
                                        x=2*x;
                                }
                                else
                                        break;
                        }
                        else
                                break;
                }
                else if(heap[x][0]<=heap[2*x][0] && heap[x][0]<=heap[2*x+1][0])
                        break;
                else
                {
                        if(heap[2*x][0]<=heap[2*x+1][0])
                        {
                                pt[heap[x][1]]=2*x;
                                pt[heap[2*x][1]]=x;
                                int temp=heap[x][0];
                                int temp2=heap[x][1];
                                heap[x][0]=heap[2*x][0];
                                heap[x][1]=heap[2*x][1];
                                heap[2*x][0]=temp;
                                heap[2*x][1]=temp2;
                                x=2*x;
                        }
                        else
                        {
                                pt[heap[x][1]]=2*x+1;
                                pt[heap[2*x+1][1]]=x;
                                int temp=heap[x][0];
                                int temp2=heap[x][1];
                                heap[x][0]=heap[2*x+1][0];
                                heap[x][1]=heap[2*x+1][1];
                                heap[2*x+1][0]=temp;
                                heap[2*x+1][1]=temp2;
                                x=2*x+1;
                        }
                }
        }
        return ret;
}

void dikstra(int u,int v)
{
        while(ptr!=1)
        {
                int v=hdeletemin();
                node *temp=ar[v];
                while(temp!=NULL)
                {
                        int w=temp->val;
                        if(d[v]+temp->weight < d[w])
                        {
                                d[w]=d[v]+temp->weight;
                                decpty(d[w],pt[w]);
                        }
                        temp=temp->next;
                }
        }
}*/

/*int main()
  {
  int n,m,u,v,w,i;
  scanf("%d%d",&n,&m);
  for(i=0;i<=n;i++)
  state[i]=0;
  while(m--)
  {
  scanf("%d%d%d",&u,&v,&w);
  insert(u,v,w);
  }
  scanf("%d%d",&u,&v);
  ptr=1;
  hinsert(0,u);
  d[u]=0;
  for(i=1;i<=n;i++)
  {
  if(i!=u)
  {
  hinsert(1000000000,i);
  d[i]=1000000000;
  }
  }
  dikstra(u,v);
  if(d[v]==1000000000)
  printf("NO\n");
  else
  printf("%d\n",d[v]);
  return 0;
  }*/

//kruskal + dsu

//int dsu[N];
/*int find(int x)
{
        if(dsu[x]==x)return x;
        return dsu[x] = find(dsu[x]);
}

void Union(int a,int b)
{
        if(a==b)
                return;
        dsu[a] = b;
}

typedef struct edge
{
        int u,v;
        int weight;
}edge;
*/
//edge e[N];
/*int cmp(const void *a,const void *b)
  {
  return ((edge*)a)->weight - ((edge*)b)->weight;
  }*/
/*int main()
  {
  int i;
  int n,m;
  scanf("%d %d\n",&n,&m);
  for(i=0;i<m;i++)
  scanf("%d %d %d",&e[i].u,&e[i].v,&e[i].weight);
  for(i=1;i<=n;i++)
  dsu[i]=i;
  qsort(e,m,sizeof(edge),cmp);
  long long int sum=0;
  for(i=0;i<m;i++)
  {
  int a,b;
  if((a=find(e[i].u))!=(b=find(e[i].v)))
  {
  sum+=e[i].weight;
  Union(a,b);
  }
  }
  printf("%lld\n",sum);
  return 0;
  }*/

//qsort

/*int cmpfunc(const void *a,const void *b)
{
        return (*(int *)a - *(int *)b);
}*/
//qsort(ar,n,sizeof(int),cmpfunc);

//-------------------------------------------------------------------------------------------------------------------------------------

int main()
{
        int n,v,a[3001],pre,val1,val2,ans=0,i;
        scan(n);
        scan(v);
        pre=0;
        int max=0;
        for(i=0;i<3001;i++)
                a[i]=0;
        for(i=0;i<n;i++)
        {
                scan(val1);
                scan(val2);
                a[val1]+=val2;
                if(val1>max)
                        max=val1;
        }
        for(i=1;i<=max+1;i++)
        {
                if(pre<=v)
                {
                        ans+=pre;
                        int x=v-pre;
                        if(a[i]<=x)
                        {
                                ans+=a[i];
                                pre=0;
                        }
                        else
                        {
                                ans+=x;
                                pre=a[i]-x;
                        }

                }
                else
                {
                        ans+=v;
                        pre=a[i];
                }
        }
        print(ans);
        return 0;
}


#include<stdio.h>
int main()
{
long int n,v,t,a,b,A[3002]={0},i,count=0;
scanf("%ld%ld",&n,&v);
t=n;
while(n--)
{
scanf("%ld%ld",&a,&b);
A[a]+=b;
//printf("%ld\n",A[a]);
}
if(A[1]>v)
{
count+=v;
//printf("count1 %d\n",count);
A[1]-=v;
}
else
{
count+=A[1];

//printf("count2 %d\n",count);
A[1]=0;
}
for(i=2;i<=3002;i++)
{
//if(A[i]!=0)
//printf("hello\n");
if(A[i-1]>0)
{
    if(A[i-1]>v)
    {
       count+=v;

//printf("count3 %d\n",count);
       A[i-1]-=v;
    }
    else
     {
          count+=A[i-1];

//printf("count4 %d\n",count);

      if(A[i]>0)
       {
          if(A[i]>v-A[i-1])
           {
           count+=v-A[i-1];

//printf("count5 %d\n",count);
           A[i]=A[i]-(v-A[i-1]);
           }
          else
            {
            count+=A[i];

//printf("count6 %d\n",count);
            A[i]=0;
            }
A[i-1]=0;
       }
    }
}
else
{
if(A[i]>0)
{
    if(A[i]>v)
   { count+=v;

//printf("count7 %d\n",count);
    A[i]-=v;}
  else
   {
   count+=A[i];

//printf("count8 %d\n",count);
   A[i]=0;
   }

}

}
}
printf("%ld",count);
return 0;
}


#include<stdio.h>
int main()
{
long int n,v,t,a,b,A[3002]={0},i,count=0;
scanf("%ld%ld",&n,&v);
t=n;
while(n--)
{
scanf("%ld%ld",&a,&b);
A[a]+=b;
//printf("%ld\n",A[a]);
}
if(A[1]>v)
{
count+=v;
//printf("count1 %d\n",count);
A[1]-=v;
}
else
{
count+=A[1];

//printf("count2 %d\n",count);
A[1]=0;
}
for(i=2;i<=3001;i++)
{
//if(A[i]!=0)
//printf("hello\n");
if(A[i-1]>0)
{
    if(A[i-1]>v)
    {
       count+=v;

//printf("count3 %d\n",count);
       A[i-1]-=v;
    }
    else
     {
          count+=A[i-1];

//printf("count4 %d\n",count);

      if(A[i]>0)
       {
          if(A[i]>v-A[i-1])
           {
           count+=v-A[i-1];

//printf("count5 %d\n",count);
           A[i]=A[i]-(v-A[i-1]);
           }
          else
            {
            count+=A[i];

//printf("count6 %d\n",count);
            A[i]=0;
            }
A[i-1]=0;
       }
    }
}
else
{
if(A[i]>0)
{
    if(A[i]>v)
   { count+=v;

//printf("count7 %d\n",count);
    A[i]-=v;}
  else
   {
   count+=A[i];

//printf("count8 %d\n",count);
   A[i]=0;
   }

}

}
}
printf("%ld",count);
return 0;
}


#include<stdio.h>
int main()
{
long int n,v,t,a,b,A[3002]={0},i,count=0;
scanf("%ld%ld",&n,&v);
t=n;
while(n--)
{
scanf("%ld%ld",&a,&b);
A[a]+=b;
}
if(A[1]>v)
{
count+=v;
//printf("count1 %d\n",count);
A[1]-=v;
}
else
{
count+=A[1];

//printf("count2 %d\n",count);
A[1]=0;
}
for(i=2;i<=t+1;i++)
{
if(A[i-1]>0)
{
    if(A[i-1]>v)
    {
       count+=v;

//printf("count3 %d\n",count);
       A[i-1]-=v;
    }
    else
     {
          count+=A[i-1];

//printf("count4 %d\n",count);

      if(A[i]>0)
       {
          if(A[i]>v-A[i-1])
           {
           count+=v-A[i-1];

//printf("count5 %d\n",count);
           A[i]=A[i]-(v-A[i-1]);
           }
          else
            {
            count+=A[i];

//printf("count6 %d\n",count);
            A[i]=0;
            }
A[i-1]=0;
       }
    }
}
else
{
if(A[i]>0)
{
    if(A[i]>v)
   { count+=v;

//printf("count7 %d\n",count);
    A[i]-=v;}
  else
   {
   count+=A[i];

//printf("count8 %d\n",count);
   A[i]=0;
   }

}

}
}
printf("%ld",count);
return 0;
}


#include<stdio.h>
int main()
{
int n,v,t,a,b,A[3002]={0},i,count=0;
scanf("%d%d",&n,&v);
t=n;
while(n--)
{
scanf("%d%d",&a,&b);
A[a]+=b;
}
if(A[1]>v)
{
count+=v;
//printf("count1 %d\n",count);
A[1]-=v;
}
else
{
count+=A[1];

//printf("count2 %d\n",count);
A[1]=0;
}
for(i=2;i<=t+1;i++)
{
if(A[i-1]>0)
{
    if(A[i-1]>v)
    {
       count+=v;

//printf("count3 %d\n",count);
       A[i-1]-=v;
    }
    else
     {
          count+=A[i-1];

//printf("count4 %d\n",count);

      if(A[i]>0)
       {
          if(A[i]>v-A[i-1])
           {
           count+=v-A[i-1];

//printf("count5 %d\n",count);
           A[i]=A[i]-(v-A[i-1]);
           }
          else
            {
            count+=A[i];

//printf("count6 %d\n",count);
            A[i]=0;
            }
A[i-1]=0;
       }
    }
}
else
{
if(A[i]>0)
{
    if(A[i]>v)
   { count+=v;

//printf("count7 %d\n",count);
    A[i]-=v;}
  else
   {
   count+=A[i];

//printf("count8 %d\n",count);
   A[i]=0;
   }

}

}
}
printf("%d",count);
return 0;
}


#include<stdio.h>
#include<malloc.h>
typedef struct xxx
{
    int a,b;
}fruit;
fruit ar[3000];
int days[3002];
void merge(fruit *a,fruit *b,fruit *c,int n,int m)
{
    int i=0,j=0,k=0;
    while(i<n && j<m)
    {
        if(a[i].a<b[j].a)
            c[k++]=a[i++];
        else if(a[i].a>b[j].a)
            c[k++]=b[j++];
        else
        {
            if(a[i].b<=b[j].b)
                c[k++]=a[i++];
            else
                c[k++]=b[j++];
        }
    }
    while(i<n)
    {
        c[k++]=a[i++];
    }
    while(j<m)
        c[k++]=b[j++];
}
void mergesort(fruit *a,int n)
{
    if(n<=1)
        return ;
    fruit *b=(fruit *)malloc(n*sizeof(fruit));
    int i,mid=n/2;
    mergesort(a,mid);
    mergesort(a+mid,n-mid);
    merge(a,a+mid,b,mid,n-mid);
    for(i=0;i<n;i++)
        a[i]=b[i];
    free(b);
}
int main()
{
    int n,v,i;
    long long int ans=0;
    scanf("%d%d",&n,&v);
    for(i=0;i<n;i++)
    {
        scanf("%d%d",&ar[i].a,&ar[i].b);
    }
    mergesort(ar,n);
    for(i=0;i<n;i++)
    {
        if(v-days[ar[i].a]>0)
        {
            days[ar[i].a]+=ar[i].b;
            ar[i].b=0;
            if(days[ar[i].a]>v)
            {
                ar[i].b=days[ar[i].a]-v;
                days[ar[i].a]=v;

            }
        }
        if(v-days[ar[i].a+1]>0)
        {
            days[ar[i].a+1]+=ar[i].b;
            ar[i].b=0;
            if(days[ar[i].a+1]>v)
            {
                ar[i].b=days[ar[i].a+1]-v;
                days[ar[i].a+1]=v;

            }
        }
    }
    for(i=0;i<=3001;i++)
        ans+=days[i];
    printf("%I64d",ans);
    return 0;
}


#include <stdio.h>

#define A	3000

int main() {
	static int bb[A + 2];
	int n, v, w, a, b, sum;

	scanf("%d%d", &n, &v);
	while (n-- > 0) {
		scanf("%d%d", &a, &b);
		bb[a] += b;
	}
	sum = 0;
	for (a = 1; a <= A + 1; a++) {
		w = v;
		if (bb[a - 1] > w)
			bb[a - 1] -= w, w = 0;
		else
			w -= bb[a - 1], bb[a - 1] = 0;
		if (bb[a] > w)
			bb[a] -= w, w = 0;
		else
			w -= bb[a], bb[a] = 0;
		sum += v - w;
	}
	printf("%d\n", sum);
	return 0;
}


#include <stdio.h>

#define A	3000

int main() {
	static int bb[A + 1];
	int n, v, w, a, b, sum;

	scanf("%d%d", &n, &v);
	while (n-- > 0) {
		scanf("%d%d", &a, &b);
		bb[a] += b;
	}
	sum = 0;
	for (a = 1; a <= A; a++) {
		w = v;
		if (bb[a - 1] > w)
			bb[a - 1] -= w, w = 0;
		else
			w -= bb[a - 1], bb[a - 1] = 0;
		if (bb[a] > w)
			bb[a] -=  w, w = 0;
		else
			w -= bb[a], bb[a] = 0;
		sum += v - w;
	}
	printf("%d\n", sum);
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}
int min(int a, int b)
{
    if(a<b)
    return a;
    else
    return b;
}
int main()
{
    int n,v,i,array[100000],count,ch,a,b;
    for(i=0;i<10000;i++)
    array[i]=0;
    scanf("%d %d",&n,&v);
    for(i=1;i<=n;i++)
    {
        scanf("%d %d",&a,&b);
        array[a]=array[a]+b;
    }
    count=0;
    for(i=1;i<=5000;i++)
    {

        count=count+min(array[i-1],v);
        if(array[i-1]<v)
        {
            ch=v-array[i-1];
            count=count+min(ch,array[i]);
            array[i]=array[i]-min(ch,array[i]);

        }
    }
    printf("%d ",count);
    return 0;
}


#include<stdio.h>

int main()
{
    int n,v,vremain,i,day,produ,total=0;
    scanf("%d%d",&n,&v);
    int a[3010]={0};
    int b[3010]={0};
    for(i=0;i<n;i++)
    {
        scanf("%d%d",&day,&produ);
        a[day]+=produ;
    }
    for(i=1;i<3010;i++)
    {
        vremain=v;
        if(a[i]||b[i])
        {
            if(b[i]<=vremain)
                {total+=b[i];
                 vremain-=b[i];
                }
            else
            {
                total+=vremain;
                b[i+1]=a[i];
                vremain=0;
            }
            if(a[i]<=vremain)
                total+=a[i];
            else
            {
                total+=vremain;
                b[i+1]=a[i]-vremain;
            }
        }
    }
    printf("%d",total);
    return 0;

}


#include <stdio.h>
#define MAX 3005

struct s{
	int new;
	int old;
	};

struct s a[MAX];

int main(void) {
	// your code goes here
	int n,v,i;
	int rem,count=0,day,num;

	scanf("%d%d",&n,&v);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&day);   scanf("%d",&num);
		a[day].new=(a[day].new)+num;
	}
	for(i=1;i<=(n+1);i++)
	{
		if(v>=(a[i].old+a[i].new))
		{
			count=count+a[i].old+a[i].new;
			a[i+1].old=0;
		}
		else if(v<(a[i].old+a[i].new))
		{
			if(v>=a[i].old)
			{
				count=count+a[i].old;
				rem=v-a[i].old;
				if(a[i].new<=rem)
				{
					count=count+a[i].new;  a[i+1].old=0;
				}
				else if(a[i].new>rem)
				{
					count=count+rem;   a[i+1].old=a[i].new-rem;
				}
			}
			else if(v<a[i].old)
			{
				count=count+v;
				a[i+1].old=a[i].new;
			}
		}
	}

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

	return 0;
}


#include <stdio.h>
#define MAX 3005

struct s{
	int new;
	int old;
	};

struct s a[MAX];

int main(void) {
	// your code goes here
	int n,v,i;
	int rem,count=0,day,num;

	scanf("%d%d",&n,&v);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&day);   scanf("%d",&num);
		a[day].new=(a[day].new)+num;
	}
	for(i=1;i<=(3000+1);i++)
	{
		if(v>=(a[i].old+a[i].new))
		{
			count=count+a[i].old+a[i].new;
			a[i+1].old=0;
		}
		else if(v<(a[i].old+a[i].new))
		{
			if(v>=a[i].old)
			{
				count=count+a[i].old;
				rem=v-a[i].old;
				if(a[i].new<=rem)
				{
					count=count+a[i].new;  a[i+1].old=0;
				}
				else if(a[i].new>rem)
				{
					count=count+rem;   a[i+1].old=a[i].new-rem;
				}
			}
			else if(v<a[i].old)
			{
				count=count+v;
				a[i+1].old=a[i].new;
			}
		}
	}

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

	return 0;
}


#include <stdio.h>

int A[3002];

int main()
{
    int N, V, a, b, i, Sum;
    scanf("%d %d", &N, &V);
    for(i=0; i<N; ++i)
    {
        scanf("%d %d", &a, &b);
        A[a] += b;
    }
    int need, have, min;
    for(i=3001; i>0; --i)
    {
        if(A[i] < V && A[i-1] > 0)
        {
            need = V - A[i];
            have = A[i-1];
            min = need < have ? need : have;
            A[i] += min;
            A[i-1] -= min;
        }
        else if(A[i] > V)
        {
            A[i] = V;
        }
    }
    for(Sum=i=0; i<3002; ++i)
    {
        Sum += A[i];
    }
    printf("%d\n", Sum);
    return 0;
}


#include <stdio.h>

int A[3002];

int main()
{
    int N, V, a, b, i, Sum;
    scanf("%d %d", &N, &V);
    for(i=0; i<N; ++i)
    {
        scanf("%d %d", &a, &b);
        if(A[a] + b > V)
        {
            int temp = V - A[a];
            A[a] = V;
            A[a+1] += b-temp;
            if(A[a+1] > V)
            {
                A[a+1] = V;
            }
        }
        else
        {
            A[a] = V;
        }
    }
    for(Sum=i=0; i<3002; ++i)
    {
        Sum += A[i];
    }
    printf("%d\n", Sum);
    return 0;
}


#include<stdio.h>
#define DAY 3002
int main() {
	int n,v;
	scanf("%d%d",&n,&v);
	int i;
	int fruit[DAY];
	for(i=0;i<DAY;i++){
		fruit[i]=0;
	}
	int last_day=0;
	for(i=0;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		fruit[a]+=b;
		if(a>last_day)last_day=a;
	}
	int sum=0;
	int day=1;
	int remain=0;
	while(1){
		if(day>last_day+1)break;
		//优先处理前一天留下来的
		if(remain>0){
			if(remain>=v){
				sum+=v;
				remain=fruit[day];
			}else{
				if(remain+fruit[day]>=v){
					sum+=v;
					remain=remain+fruit[day]-v;
				}else{
					sum+=remain+fruit[day];
					remain=0;
				}
			}
		}else{
			if(fruit[day]<=v){
				sum+=fruit[day];
				remain=0;
			}else{
				remain=fruit[day]-v;
				sum+=v;
			}
		}
		day++;
	}
	printf("%d\n",sum);
	return 0;
}


#include <stdio.h>
int a[5000];
int b[5000] = {0};
int n, v;
int min(int x, int y)
{
    return x<y?x:y;
}
int max(int x, int y)
{
    return x>y?x:y;
}
int main()
{
    scanf ( "%d%d", &n, &v );
    int i;
    for(i=0; i<n; i++)
    {
        int x, y;
        scanf ( "%d%d", &x, &y );
        b[x] += y;
    }
    for(i=3000; i>=1; i--)
    {
        if(b[i+1] <= v)
        {
            int t;
            if(b[i] - (v-b[i+1]) >= 0)
                t = v - b[i+1];
            else
                t = b[i];
            b[i] -= t;
            b[i+1] += t;
        }
    }
    int ans = 0;
    for(i=1; i<=3001; i++)
    {
        ans += min(v, b[i]);
    }
    printf ( "%d\n", ans );
    return 0;
}


#include<stdio.h>

unsigned int main (void){

    unsigned int v,n,max=0;

	fscanf(stdin,"%d %d",&n,&v);
	unsigned int i =0;
	unsigned int day[3002];
	for(i = 0 ; i < 3002 ;i++){
        day[i] = 0;
	}
	unsigned int j,k;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] += k;
		if(max < j)
			max = j;
	}

//	for(i = 1 ; i <=n ;i++){
//
//		prunsigned intf("day[%d] = %d \n",i,day[i]);
//
//	}

    unsigned int left[3002],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= max+1 ; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }

        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
    if(left[i-1]<=v){
       fruit = fruit + left[i-1];
       if(v-left[i-1] >= day[i]){
            fruit = fruit + day[i];
			left[i]=0;
       }
       else{
            fruit = fruit + v - left[i-1];
            left[i] = day[i] - v +left[i-1];
       }
    }
    else{
        fruit = fruit + v;
        left[i] = day[i];

    }

    }
// prunsigned intf("%d\n",left[i]);
//
  //   prunsigned intf("%d\n",fruit);

}
     // prunsigned intf("%d\n",left[2]);
     printf("%d\n",fruit);
     return 0;
}


#include<stdio.h>

int main (void){

	int v,n;

	fscanf(stdin,"%d %d",&n,&v);
	int i =0;
	int day[3000] = {0};
//	for(i = 0 ; i < n+2 ;i++){
//        day[i] = 0;
//	}
	int j,k,max =0;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] += k;
		if(j > max){
            max =j;
		}

	}

//	for(i = 1 ; i <=n ;i++){
//
//		printf("day[%d] = %d \n",i,day[i]);
//
//	}

    int left[max+1],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= max + 1; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }
        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
        if(left[i-1]<=v){
           fruit = fruit + left[i-1];
           if(v-left[i-1] >= day[i]){
                fruit = fruit + day[i];
                left[i] = 0;
           }
           else{
                fruit = fruit + v - left[i-1];
                left[i] = day[i] - v +left[i-1];
           }

        }
        else{
            fruit = fruit + v;
            left[i] = day[i];

        }
    }
// printf("%d\n",left[i]);
//
  //   printf("%d\n",fruit);

}
     // printf("%d\n",left[2]);
     printf("%d",fruit);
     return 0;
}


#include<stdio.h>

int main (void){

	int v,n;

	fscanf(stdin,"%d %d",&n,&v);
	int i =0;
	int day[n+1];
	int j,k;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] = k;

	}

//	for(i = 1 ; i <=n ;i++){
//
//		printf("day[%d] = %d \n",i,day[i]);
//
//	}
    day[n+1] = 0;
    int left[n],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= n+1 ; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }

        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
    if(left[i-1]<=v){
       fruit = fruit + left[i-1];
       if(v-left[i-1] >= day[i]){
            fruit = fruit + day[i];
       }
       else{
            fruit = fruit + v - left[i-1];
            left[i] = day[i] - v +left[i-1];
       }
    }
    else{
        fruit = fruit + v;
        left[i] = day[i];

    }

    }
// printf("%d\n",left[i]);
//
  //   printf("%d\n",fruit);

}
     // printf("%d\n",left[2]);
     printf("%d",fruit);
     return 0;
}


#include<stdio.h>

int main (void){

	int v,n,max=0;

	fscanf(stdin,"%d %d",&n,&v);
	int i =0;
	int day[3000] = {0};

	int j,k;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] += k;
		if(max < j)
			max = j;
	}

//	for(i = 1 ; i <=n ;i++){
//
//		printf("day[%d] = %d \n",i,day[i]);
//
//	}

    int left[n],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= max+1 ; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }

        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
    if(left[i-1]<=v){
       fruit = fruit + left[i-1];
       if(v-left[i-1] >= day[i]){
            fruit = fruit + day[i];
			left[i]=0;
       }
       else{
            fruit = fruit + v - left[i-1];
            left[i] = day[i] - v +left[i-1];
       }
    }
    else{
        fruit = fruit + v;
        left[i] = day[i];

    }

    }
// printf("%d\n",left[i]);
//
  //   printf("%d\n",fruit);

}
     // printf("%d\n",left[2]);
     printf("%d",fruit);
     return 0;
}


#include<stdio.h>

int main (void){

	int v,n;

	fscanf(stdin,"%d %d",&n,&v);
	int i =0;
	int day[3000] = {0};
//	for(i = 0 ; i < n+2 ;i++){
//        day[i] = 0;
//	}
	int j,k,max =0;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] += k;
		if(j > max){
            max =j;
		}

	}

//	for(i = 1 ; i <=n ;i++){
//
//		printf("day[%d] = %d \n",i,day[i]);
//
//	}

    int left[max+1],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= max + 1; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }

        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
    if(left[i-1]<=v){
       fruit = fruit + left[i-1];
       if(v-left[i-1] >= day[i]){
            fruit = fruit + day[i];
       }
       else{
            fruit = fruit + v - left[i-1];
            left[i] = day[i] - v +left[i-1];
       }
    }
    else{
        fruit = fruit + v;
        left[i] = day[i];

    }

    }
// printf("%d\n",left[i]);
//
  //   printf("%d\n",fruit);

}
     // printf("%d\n",left[2]);
     printf("%d",fruit);
     return 0;
}


#include<stdio.h>

int main (void){

	int v,n;

	fscanf(stdin,"%d %d",&n,&v);
	int i =0;
	int day[n+1];
	int j,k;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] = k;

	}

//	for(i = 1 ; i <=n ;i++){
//
//		printf("day[%d] = %d \n",i,day[i]);
//
//	}
    day[n+1] = 0;
    int left[n],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= n+1 ; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }

        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
    if(left[i-1]<=v){
       fruit = fruit + left[i-1];
       if(v-left[i-1] >= day[i]){
            fruit = fruit + day[i];
       }
       else{
            fruit = fruit + v - left[i-1];
            left[i] = day[i] - v +left[i-1];
       }
    }
    else{
        fruit = fruit + v;
        left[i] = day[i];

    }

    }
// printf("%d\n",left[i]);
//
  //   printf("%d\n",fruit);

}
     // printf("%d\n",left[2]);
     printf("%u",fruit);
     return 0;
}


#include<stdio.h>

int main (void){

	int v,n,max=0;

	fscanf(stdin,"%d %d",&n,&v);
	int i =0;
	int day[3000];
	int j,k;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] += k;
		if(max < j)
			max = j;
	}

//	for(i = 1 ; i <=n ;i++){
//
//		printf("day[%d] = %d \n",i,day[i]);
//
//	}

    int left[n],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= max+1 ; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }

        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
    if(left[i-1]<=v){
       fruit = fruit + left[i-1];
       if(v-left[i-1] >= day[i]){
            fruit = fruit + day[i];
			left[i]=0;
       }
       else{
            fruit = fruit + v - left[i-1];
            left[i] = day[i] - v +left[i-1];
       }
    }
    else{
        fruit = fruit + v;
        left[i] = day[i];

    }

    }
// printf("%d\n",left[i]);
//
  //   printf("%d\n",fruit);

}
     // printf("%d\n",left[2]);
     printf("%d",fruit);
     return 0;
}


#include<stdio.h>

int main (void){

	int v,n;

	fscanf(stdin,"%d %d",&n,&v);
	int i =0;
	int day[3000] = {0};
//	for(i = 0 ; i < n+2 ;i++){
//        day[i] = 0;
//	}
	int j,k,max =0;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] += k;
		if(j > max){
            max =j;
		}

	}

//	for(i = 1 ; i <=n ;i++){
//
//		printf("day[%d] = %d \n",i,day[i]);
//
//	}

    int left[n],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= max+1 ; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }

        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
    if(left[i-1]<=v){
       fruit = fruit + left[i-1];
       if(v-left[i-1] >= day[i]){
            fruit = fruit + day[i];
       }
       else{
            fruit = fruit + v - left[i-1];
            left[i] = day[i] - v +left[i-1];
       }
    }
    else{
        fruit = fruit + v;
        left[i] = day[i];

    }

    }
// printf("%d\n",left[i]);
//
  //   printf("%d\n",fruit);

}
     // printf("%d\n",left[2]);
     printf("%d",fruit);
     return 0;
}


#include<stdio.h>

int main (void){

	int v,n,max=0;

	fscanf(stdin,"%d %d",&n,&v);
	int i =0;
	int day[3000];
	for(i = 0 ; i < n+2 ;i++){
        day[i] = 0;
	}
	int j,k;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] += k;
		if(max < j)
			max = j;
	}

//	for(i = 1 ; i <=n ;i++){
//
//		printf("day[%d] = %d \n",i,day[i]);
//
//	}

    int left[n],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= max+1 ; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }

        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
    if(left[i-1]<=v){
       fruit = fruit + left[i-1];
       if(v-left[i-1] >= day[i]){
            fruit = fruit + day[i];
			left[i]=0;
       }
       else{
            fruit = fruit + v - left[i-1];
            left[i] = day[i] - v +left[i-1];
       }
    }
    else{
        fruit = fruit + v;
        left[i] = day[i];

    }

    }
// printf("%d\n",left[i]);
//
  //   printf("%d\n",fruit);

}
     // printf("%d\n",left[2]);
     printf("%d",fruit);
     return 0;
}


#include<stdio.h>

int main (void){

	int v,n,max=0;

	fscanf(stdin,"%d %d",&n,&v);
	int i =0;
	int day[3002];
	for(i = 0 ; i < 3002 ;i++){
        day[i] = 0;
	}
	int j,k;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] += k;
		if(max < j)
			max = j;
	}

//	for(i = 1 ; i <=n ;i++){
//
//		printf("day[%d] = %d \n",i,day[i]);
//
//	}

    int left[n],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= max+1 ; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }

        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
    if(left[i-1]<=v){
       fruit = fruit + left[i-1];
       if(v-left[i-1] >= day[i]){
            fruit = fruit + day[i];
			left[i]=0;
       }
       else{
            fruit = fruit + v - left[i-1];
            left[i] = day[i] - v +left[i-1];
       }
    }
    else{
        fruit = fruit + v;
        left[i] = day[i];

    }

    }
// printf("%d\n",left[i]);
//
  //   printf("%d\n",fruit);

}
     // printf("%d\n",left[2]);
     printf("%d",fruit);
     return 0;
}


#include<stdio.h>

int main (void){

	int v,n;

	fscanf(stdin,"%d %d",&n,&v);
	int i =0;
	int day[n+2];
	for(i = 0 ; i < n+2 ;i++){
        day[i] = 0;
	}
	int j,k;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] = k;

	}

//	for(i = 1 ; i <=n ;i++){
//
//		printf("day[%d] = %d \n",i,day[i]);
//
//	}
    day[n+1] = 0;
    int left[n],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= n+1 ; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }

        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
    if(left[i-1]<=v){
       fruit = fruit + left[i-1];
       if(v-left[i-1] >= day[i]){
            fruit = fruit + day[i];
       }
       else{
            fruit = fruit + v - left[i-1];
            left[i] = day[i] - v +left[i-1];
       }
    }
    else{
        fruit = fruit + v;
        left[i] = day[i];

    }

    }
// printf("%d\n",left[i]);
//
  //   printf("%d\n",fruit);

}
     // printf("%d\n",left[2]);
     printf("%d",fruit);
     return 0;
}


#include<stdio.h>

int main (void){

	int v,n;

	fscanf(stdin,"%d %d",&n,&v);
	int i =0;
	int day[n+2];
	for(i = 0 ; i < n+2 ;i++){
        day[i] = 0;
	}
	int j,k;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] = k;

	}

//	for(i = 1 ; i <=n ;i++){
//
//		printf("day[%d] = %d \n",i,day[i]);
//
//	}
    day[n+1] = 0;
    int left[n],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= n+2 ; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }

        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
    if(left[i-1]<=v){
       fruit = fruit + left[i-1];
       if(v-left[i-1] >= day[i]){
            fruit = fruit + day[i];
       }
       else{
            fruit = fruit + v - left[i-1];
            left[i] = day[i] - v +left[i-1];
       }
    }
    else{
        fruit = fruit + v;
        left[i] = day[i];

    }

    }
// printf("%d\n",left[i]);
//
  //   printf("%d\n",fruit);

}
     // printf("%d\n",left[2]);
     printf("%d",fruit);
     return 0;
}


#include<stdio.h>

int main (void){

	int v,n,max=0;

	fscanf(stdin,"%d %d",&n,&v);
	int i =0;
	int day[3000];
	for(i = 0 ; i <= 3000 ;i++){
        day[i] = 0;
	}
	int j,k;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] += k;
		if(max < j)
			max = j;
	}

//	for(i = 1 ; i <=n ;i++){
//
//		printf("day[%d] = %d \n",i,day[i]);
//
//	}

    int left[n],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= max+1 ; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }

        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
    if(left[i-1]<=v){
       fruit = fruit + left[i-1];
       if(v-left[i-1] >= day[i]){
            fruit = fruit + day[i];
			left[i]=0;
       }
       else{
            fruit = fruit + v - left[i-1];
            left[i] = day[i] - v +left[i-1];
       }
    }
    else{
        fruit = fruit + v;
        left[i] = day[i];

    }

    }
// printf("%d\n",left[i]);
//
  //   printf("%d\n",fruit);

}
     // printf("%d\n",left[2]);
     printf("%d",fruit);
     return 0;
}


#include<stdio.h>

int main (void){

	int v,n;

	fscanf(stdin,"%d %d",&n,&v);
	int i =0;
	int day[3000] = {0};
//	for(i = 0 ; i < n+2 ;i++){
//        day[i] = 0;
//	}
	int j,k,max =0;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] += k;
		if(j > max){
            max =j;
		}

	}

//	for(i = 1 ; i <=n ;i++){
//
//		printf("day[%d] = %d \n",i,day[i]);
//
//	}

    int left[n],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= max ; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }

        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
    if(left[i-1]<=v){
       fruit = fruit + left[i-1];
       if(v-left[i-1] >= day[i]){
            fruit = fruit + day[i];
       }
       else{
            fruit = fruit + v - left[i-1];
            left[i] = day[i] - v +left[i-1];
       }
    }
    else{
        fruit = fruit + v;
        left[i] = day[i];

    }

    }
// printf("%d\n",left[i]);
//
  //   printf("%d\n",fruit);

}
     // printf("%d\n",left[2]);
     printf("%d",fruit);
     return 0;
}


#include<stdio.h>

int main (void){

	int v,n,max=0;

	fscanf(stdin,"%d %d",&n,&v);
	int i =0;
	int day[3000];
	for(i = 0 ; i < 3000 ;i++){
        day[i] = 0;
	}
	int j,k;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] += k;
		if(max < j)
			max = j;
	}

//	for(i = 1 ; i <=n ;i++){
//
//		printf("day[%d] = %d \n",i,day[i]);
//
//	}

    int left[n],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= max+1 ; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }

        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
    if(left[i-1]<=v){
       fruit = fruit + left[i-1];
       if(v-left[i-1] >= day[i]){
            fruit = fruit + day[i];
			left[i]=0;
       }
       else{
            fruit = fruit + v - left[i-1];
            left[i] = day[i] - v +left[i-1];
       }
    }
    else{
        fruit = fruit + v;
        left[i] = day[i];

    }

    }
// printf("%d\n",left[i]);
//
  //   printf("%d\n",fruit);

}
     // printf("%d\n",left[2]);
     printf("%d",fruit);
     return 0;
}


#include<stdio.h>

int main (void){

	int v,n;

	fscanf(stdin,"%d %d",&n,&v);
	int i =0;
	int day[n+2];
	for(i = 0 ; i < n+2 ;i++){
        day[i] = 0;
	}
	int j,k;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] += k;

	}

//	for(i = 1 ; i <=n ;i++){
//
//		printf("day[%d] = %d \n",i,day[i]);
//
//	}
    day[n+1] = 0;
    int left[n],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= n+1 ; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }

        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
    if(left[i-1]<=v){
       fruit = fruit + left[i-1];
       if(v-left[i-1] >= day[i]){
            fruit = fruit + day[i];
			left[i]=0;
       }
       else{
            fruit = fruit + v - left[i-1];
            left[i] = day[i] - v +left[i-1];
       }
    }
    else{
        fruit = fruit + v;
        left[i] = day[i];

    }

    }
// printf("%d\n",left[i]);
//
  //   printf("%d\n",fruit);

}
     // printf("%d\n",left[2]);
     printf("%d",fruit);
     return 0;
}


#include<stdio.h>

int main (void){

	int v,n;

	fscanf(stdin,"%d %d",&n,&v);
	int i =0;
	int day[n+2];
	for(i = 0 ; i < n+2 ;i++){
        day[i] = 0;
	}
	int j,k;
	for(i = 1; i <= n ; i++){

		fscanf(stdin,"%d %d",&j,&k);
		day[j] += k;

	}

//	for(i = 1 ; i <=n ;i++){
//
//		printf("day[%d] = %d \n",i,day[i]);
//
//	}
    day[n+1] = 0;
    int left[n],fruit = 0;
    left[0] = 0;
    for(i = 1; i <= n+1 ; i++){

    if (left[i-1] == 0){
        if(v >= day[i]){
            fruit = fruit+day[i];
            left[i] = 0;
        }

        if (v<day[i]){
            fruit = fruit + v;
            left[i] = day[i]-v;

        }
    }
    else {
    if(left[i-1]<=v){
       fruit = fruit + left[i-1];
       if(v-left[i-1] >= day[i]){
            fruit = fruit + day[i];
       }
       else{
            fruit = fruit + v - left[i-1];
            left[i] = day[i] - v +left[i-1];
       }
    }
    else{
        fruit = fruit + v;
        left[i] = day[i];

    }

    }
// printf("%d\n",left[i]);
//
  //   printf("%d\n",fruit);

}
     // printf("%d\n",left[2]);
     printf("%d",fruit);
     return 0;
}


#include <stdio.h>
int main()
{
    int n,v,i,sum=0,a,b;
    scanf("%d %d",&n,&v);
    int arr[n+2];
    for(i=1;i<=n+2;i++)
      arr[i]=0;
    for(i=1;i<=n;i++)
    {
        scanf("%d %d",&a,&b);
        arr[a]+=b;
    }

    for(i=1;i<=n+1;i++)
    {
        if(arr[i]>v)
        {
            sum+=v;
            arr[i+1]=arr[i+1]+arr[i]-v;
        }
        else
          sum+=arr[i];
    }
    //  for(i=1;i<=n+1;i++)
     // printf("%d ",arr[i]);
    printf("%d\n",sum);
    return 0;
}


#include <stdio.h>
int main()
{
    int n,v,i,sum=0,a,b;
    scanf("%d %d",&n,&v);
    int arr[3002];
    for(i=1;i<=3002;i++)
      arr[i]=0;
    for(i=1;i<=n;i++)
    {
        scanf("%d %d",&a,&b);
        arr[a]+=b;
    }

    for(i=1;i<=n+1;i++)
    {
        if(arr[i]>v)
        {
            sum+=v;
            arr[i]=arr[i]-v;
           if(arr[i]>v)
            arr[i+1]=arr[i+1]+v;
           else
            arr[i+1]=arr[i+1]+arr[i];
        }
        else
          sum+=arr[i];
    }
    //  for(i=1;i<=n+1;i++)
     // printf("%d ",arr[i]);
    printf("%d\n",sum);
    return 0;
}


#include <stdio.h>
//#include <time.h>

struct Pom {
    int zile, fructe;
};

int main()
{
    FILE *fisier;
    int nrPomi, nrFructePeZi;

/* masurare timp de executie
    struct timespec start, stop;
    clock_gettime(CLOCK_REALTIME, &start);
-----------------------------------------------------------------*/

    fisier = fopen("input.txt", "r");
    fscanf(fisier, "%d", &nrPomi);
    fscanf(fisier, "%d", &nrFructePeZi);

    struct Pom pom[nrPomi];

    for (int i = 0; i < nrPomi; i++) {
        fscanf(fisier, "%d", &pom[i].zile);
        fscanf(fisier, "%d", &pom[i].fructe);
        struct Pom aux = pom[i];
        int j = i;
        while (j > 0 && pom[j - 1].zile > aux.zile) {
            pom[j] = pom[j - 1];
            j--;
        }
        pom[j] = aux;
    }

    int nrTotalFructe = 0;
    int ziua0 = 0;
    int fructeCulese = 0;

    while (pom[nrPomi - 1].zile != -2) {
        fructeCulese = 0;
        for (int i = ziua0; i < nrPomi; i++) {
            if (fructeCulese < nrFructePeZi &&
               (pom[i].zile == 0 || pom[i].zile == -1)) {
                if (fructeCulese + pom[i].fructe <= nrFructePeZi) {
                    fructeCulese += pom[i].fructe;
                    pom[i].fructe = 0;
                } else {
                    pom[i].fructe -= (nrFructePeZi - fructeCulese);
                    fructeCulese = nrFructePeZi;
                }
            }
            if (--pom[i].zile == -2)
                ziua0 = i;
        }
        nrTotalFructe += fructeCulese;
    }

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

    fclose(fisier);

/* masurare timp de executie
    clock_gettime(CLOCK_REALTIME, &stop);
    double time;
    time = (double)(((int)stop.tv_sec - (int)start.tv_sec) * 1000000000 -
           start.tv_nsec + stop.tv_nsec) / 1000000000.0;
    printf("%f\n", time);
--------------------------------------------------------------------*/

    return 0;
}


#include <stdio.h>

struct Pom {
    int zile, fructe;
};

int main()
{
    int nrPomi, nrFructePeZi;
    int i;

    scanf("%d", &nrPomi);
    scanf("%d", &nrFructePeZi);

    struct Pom pom[nrPomi];

    for (i = 0; i < nrPomi; i++) {
        scanf("%d", &pom[i].zile);
        scanf("%d", &pom[i].fructe);
        struct Pom aux = pom[i];
        int j = i;
        while (j > 0 && pom[j - 1].zile > aux.zile) {
            pom[j] = pom[j - 1];
            j--;
        }
        pom[j] = aux;
    }

    int nrTotalFructe = 0;
    int ziua0 = 0;
    int fructeCulese = 0;

    while (pom[nrPomi - 1].zile != -2) {
        fructeCulese = 0;
        for (i = ziua0; i < nrPomi; i++) {
            if (fructeCulese < nrFructePeZi &&
               (pom[i].zile == 0 || pom[i].zile == -1)) {
                if (fructeCulese + pom[i].fructe <= nrFructePeZi) {
                    fructeCulese += pom[i].fructe;
                    pom[i].fructe = 0;
                } else {
                    pom[i].fructe -= (nrFructePeZi - fructeCulese);
                    fructeCulese = nrFructePeZi;
                }
            }
            if (--pom[i].zile == -2)
                ziua0 = i;
        }
        nrTotalFructe += fructeCulese;
    }

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

    return 0;
}


#include <stdio.h>
#include <time.h>

struct Pom {
    int zile, fructe;
};

int main()
{
    FILE *fisier;
    int nrPomi, nrFructePeZi;

/* masurare timp de executie
    struct timespec start, stop;
    clock_gettime(CLOCK_REALTIME, &start);
-----------------------------------------------------------------*/

    fisier = fopen("input.txt", "r");
    fscanf(fisier, "%d", &nrPomi);
    fscanf(fisier, "%d", &nrFructePeZi);

    struct Pom pom[nrPomi];

    for (int i = 0; i < nrPomi; i++) {
        fscanf(fisier, "%d", &pom[i].zile);
        fscanf(fisier, "%d", &pom[i].fructe);
        struct Pom aux = pom[i];
        int j = i;
        while (j > 0 && pom[j - 1].zile > aux.zile) {
            pom[j] = pom[j - 1];
            j--;
        }
        pom[j] = aux;
    }

    int nrTotalFructe = 0;
    int ziua0 = 0;
    int fructeCulese = 0;

    while (pom[nrPomi - 1].zile != -2) {
        fructeCulese = 0;
        for (int i = ziua0; i < nrPomi; i++) {
            if (fructeCulese < nrFructePeZi &&
               (pom[i].zile == 0 || pom[i].zile == -1)) {
                if (fructeCulese + pom[i].fructe <= nrFructePeZi) {
                    fructeCulese += pom[i].fructe;
                    pom[i].fructe = 0;
                } else {
                    pom[i].fructe -= (nrFructePeZi - fructeCulese);
                    fructeCulese = nrFructePeZi;
                }
            }
            if (--pom[i].zile == -2)
                ziua0 = i;
        }
        nrTotalFructe += fructeCulese;
    }

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

    fclose(fisier);

/* masurare timp de executie
    clock_gettime(CLOCK_REALTIME, &stop);
    double time;
    time = (double)(((int)stop.tv_sec - (int)start.tv_sec) * 1000000000 -
           start.tv_nsec + stop.tv_nsec) / 1000000000.0;
    printf("%f\n", time);
--------------------------------------------------------------------*/

    return 0;
}


#include<stdio.h>
int main()
{
    int n,v,i,j,k,count=0,value,temp;
    scanf("%d %d",&n,&v);
    int a[n],b[n];
    for(i=0;i<n;i++)
    scanf("%d %d",&a[i],&b[i]);

    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i]>a[j])
            {
                temp=a[i];a[i]=a[j];a[j]=temp;
                temp=b[i];b[i]=b[j];b[j]=temp;
            }
        }
    }
     j=a[n-1];
    for(i=1;i<=j+1;i++)
    {
            value=v;
            for(k=0;k<n;k++)
            {
                if(value==0)
                break;
                if(a[k]==i||a[k]==i-1)
                    {
                    if(b[k]<=value)
                    {
                    count+=b[k];
                    value=value-b[k];
                    b[k]=0;
                    }
                    else
                    {
                    count+=value;
                    b[k]=b[k]-value;
                    value=0;
                    }
                }
        }

    }

printf("%d\n",count);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,v,i,j,k,count=0,value,temp;
    scanf("%d %d",&n,&v);
    int a[n],b[n];
    for(i=0;i<n;i++)
    scanf("%d %d",&a[i],&b[i]);

    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i]>a[j])
            {
                temp=a[i];a[i]=a[j];a[j]=temp;
                temp=b[i];b[i]=b[j];b[j]=temp;
            }
        }
    }
     j=1;
    for(i=0;i<n;i++)
    {
        if(a[i]<j)
        continue;
        if(a[i]==j)
        {
            value=v;
            for(k=0;k<n;k++)
            {
                if(value==0)
                break;
                if(a[k]==j||a[k]==j-1)
                    {
                    if(b[k]<=value)
                    {
                    count+=b[k];
                    value=value-b[k];
                    b[k]=0;
                    }
                    else
                    {
                    count+=value;
                    b[k]=b[k]-value;
                    value=0;
                    }
                }
            }
        }
        j++;
    }

for(k=0;k<n;k++)
{
    if(a[k]==i)
    {
            if(b[k]<=v)
                    {
                    count+=b[k];
                    v=v-b[k];
                    b[k]=0;
                    }
                    else
                    {
                    count+=v;
                    b[k]=b[k]-v;
                    break;
                    }
    }
}

printf("%d\n",count);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,v,i,j,k,count=0,value,temp;
    scanf("%d %d",&n,&v);
    int a[n],b[n];
    for(i=0;i<n;i++)
    scanf("%d %d",&a[i],&b[i]);

    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i]>a[j])
            {
                temp=a[i];a[i]=a[j];a[j]=temp;
                temp=b[i];b[i]=b[j];b[j]=temp;
            }
        }
    }
     j=1;
    for(i=0;i<n;i++)
    {
        if(a[i]<j)
        continue;
        if(a[i]==j)
        {
            value=v;
            for(k=0;k<n;k++)
            {
                if(value==0)
                break;
                if(a[k]==j||a[k]==j-1)
                    {
                    if(b[k]<=value)
                    {
                    count+=b[k];
                    value=value-b[k];
                    b[k]=0;
                    }
                    else
                    {
                    count+=value;
                    b[k]=b[k]-value;
                    value=0;
                    }
                }
            }
        }
        j++;
    }
temp=a[n-1];
for(k=0;k<n;k++)
{
    if(v==0)
    break;
    if(a[k]==temp)
    {
            if(b[k]<=v)
                    {
                    count+=b[k];
                    v=v-b[k];
                    b[k]=0;
                    }
                    else
                    {
                    count+=v;
                    b[k]=b[k]-v;
                    break;
                    }
    }
}

printf("%d\n",count);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,v,i,j,k,count=0,value,temp;
    scanf("%d %d",&n,&v);
    int a[n],b[n];
    for(i=0;i<n;i++)
    scanf("%d %d",&a[i],&b[i]);

    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i]>a[j])
            {
                temp=a[i];a[i]=a[j];a[j]=temp;
                temp=b[i];b[i]=b[j];b[j]=temp;
            }
        }
    }
     j=1;
    for(i=0;i<n;i++)
    {
        if(a[i]<j)
        continue;
        if(a[i]==j)
        {
            value=v;
            for(k=0;k<n;k++)
            {
                if(value==0)
                break;
                if(a[k]==j||a[k]==j-1)
                    {
                    if(b[k]<=value)
                    {
                    count+=b[k];
                    value=value-b[k];
                    b[k]=0;
                    }
                    else
                    {
                    count+=value;
                    b[k]=b[k]-value;
                    value=0;
                    }
                }
            }
        }
        j++;
    }
int max=a[n-1];
for(k=0;k<n;k++)
{
    if(a[k]==i)
    {
            if(b[k]<=v)
                    {
                    count+=b[k];
                    v=v-b[k];
                    b[k]=0;
                    }
                    else
                    {
                    count+=v;
                    b[k]=b[k]-v;
                    break;
                    }
    }
}

printf("%d\n",count);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,v,i,j,k,count=0,value,temp;
    scanf("%d %d",&n,&v);
    int a[n],b[n];
    for(i=0;i<n;i++)
    scanf("%d %d",&a[i],&b[i]);

    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i]>a[j])
            {
                temp=a[i];a[i]=a[j];a[j]=temp;
                temp=b[i];b[i]=b[j];b[j]=temp;
            }
        }
    }
     j=1;
    for(i=0;i<n;i++)
    {

        if(a[i]==j||a[i]==j-1)
        {
            value=v;
            for(k=0;k<n;k++)
            {
                if(value==0)
                break;
                if(a[k]==j||a[k]==j-1)
                    {
                    if(b[k]<=value)
                    {
                    count+=b[k];
                    value=value-b[k];
                    b[k]=0;
                    }
                    else
                    {
                    count+=value;
                    b[k]=b[k]-value;
                    value=0;
                    }
                }
            }
        }
        j++;
    }
temp=a[n-1];
for(k=0;k<n;k++)
{
    if(v==0)
    break;
    if(a[k]==temp)
    {
            if(b[k]<=v)
                    {
                    count+=b[k];
                    v=v-b[k];
                    b[k]=0;
                    }
                    else
                    {
                    count+=v;
                    b[k]=b[k]-v;
                    break;
                    }
    }
}

printf("%d\n",count);
    return 0;
}


#include <stdio.h>

int N, V;
int F[6000];
int A;

int main()
{
	int i, t;
	int d, n;
	FILE *input;

	//input = fopen("fruits.in", "r");
	//fscanf(input, "%d %d\n", &N, &V);
	scanf("%d %d\n", &N, &V);

	for(i=0; i<N; i++)
	{
		//fscanf(input, "%d %d\n", &d, &n);
		scanf("%d %d\n", &d, &n);

		F[d] += n;
	}

	for(i=1; i<=4000; i++)
	{
		t = V;
		if(F[i-1] <= t)
			t -= F[i-1];
		else
		{
			A += V;
			continue;
		}

		if(F[i] <= t)
		{
			t -= F[i];
			F[i] = 0;
			A += (V-t);
		}
		else
		{
			A += V;
			F[i] -= t;
		}
	}

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

	return 0;
}


#include<stdio.h>
int main()
{
	int n,v,i,j,a[3001][2],k,temp,nof,sum=0,rem;
	scanf("%d%d",&n,&v);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&a[i][0],&a[i][1]);
	}
	for(i=0;i<n;i++)
	{
		for(j=i;j<n;j++)
		{
			if(a[i][0]>a[j][0])
			{
				temp=a[i][0];
				a[i][0]=a[j][0];
				a[j][0]=temp;
				temp=a[i][1];
				a[i][1]=a[j][1];
				a[j][1]=temp;
			}
		}
	}
	nof=0;
	for(i=0;i<n;i++)
	{
		sum=0;
		for(j=i;j<n&&a[i][0]==a[j][0];j++)
		{
			sum+=a[j][1];
		}
		if(sum>=v)
		{
			if(i>0)
			{
				if(a[i][0]-a[i-1][0]==1)
				{
					if(rem>=0)
					{

						nof=nof+v;
						if(rem>=v)
						{
							rem=sum;
						}
						else
						{
							rem=sum+rem-v;
						}
					}
					else
					{
						nof=nof+v;
						rem=sum-v;
					}
				}
				else
				{
					nof=nof+v;
					if(rem>=v)
					{
						nof=nof+v;
					}
					else if(rem>=0)
					{
						nof=nof+rem;
					}
					rem=sum-v;
				}
			}
			else
			{
				nof=nof+v;
				rem=sum-v;
			}
		}
		else
		{
			if(i>0)
			{
				if(a[i][0]-a[i-1][0]==1)
				{
					if(rem>=0)
					{
						k=sum+rem;
						if(k>=v)
						{
							nof=nof+v;
							if(rem>=v)
							{
								rem=sum;
							}
						}
						else
						{
							nof=nof+k;
							rem=-1;
						}
					}
					else
					{
						nof=nof+sum;
						rem=-1;

					}
				}
				else
				{
					nof=nof+sum;
					if(rem>=v)
					{
						nof=nof+v;
					}
					else if(rem>=0)
					{
						nof=nof+rem;
					}
					rem=-1;
				}
			}
			else
			{
				if(a[0][1]>=v)
				{
					nof=nof+v;
					rem=a[0][1]-v;
				}
				else
				{
					nof=nof+a[0][1];
					rem=-1;
				}
			}
		}
		i=j-1;
	}
	if(rem>0)
	{
		if(rem<=v)
		nof=nof+rem;
		else
		nof=nof+v;
	}
	printf("%d\n",nof);
	return 0;
}


#include<stdio.h>
int main()
{
	int n,v,i,j,a[3001][2],k,temp,nof,sum=0,rem;
	scanf("%d%d",&n,&v);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&a[i][0],&a[i][1]);
	}
	for(i=0;i<n;i++)
	{
		for(j=i;j<n;j++)
		{
			if(a[i][0]>a[j][0])
			{
				temp=a[i][0];
				a[i][0]=a[j][0];
				a[j][0]=temp;
				temp=a[i][1];
				a[i][1]=a[j][1];
				a[j][1]=temp;
			}
		}
	}
	nof=0;
	for(i=0;i<n;i++)
	{
		sum=0;
		for(j=i;j<n&&a[i][0]==a[j][0];j++)
		{
			sum+=a[j][1];
		}
		if(sum>=v)
		{
			if(i>0)
			{
				if(a[i][0]-a[i-1][0]==1)
				{
					if(rem>=0)
					{

						nof=nof+v;
						if(rem>=v)
						{
							rem=sum;
						}
						else
						{
							rem=sum+rem-v;
						}
					}
					else
					{
						nof=nof+v;
						rem=sum-v;
					}
				}
				else
				{
					nof=nof+v;
					if(rem>=v)
					{
						nof=nof+v;
					}
					else if(rem>=0)
					{
						nof=nof+rem;
					}
					rem=sum-v;
				}
			}
			else
			{
				nof=nof+v;
				rem=sum-v;
			}
		}
		else
		{
			if(i>0)
			{
				if(a[i][0]-a[i-1][0]==1)
				{
					if(rem>=0)
					{
						k=sum+rem;
						if(k>=v)
						{
							nof=nof+v;
							if(rem>=v)
							{
								rem=sum;
							}
							else
							{
								rem=k-v;
							}
						}
						else
						{
							nof=nof+k;
							rem=-1;
						}
					}
					else
					{
						nof=nof+sum;
						rem=-1;

					}
				}
				else
				{
					nof=nof+sum;
					if(rem>=v)
					{
						nof=nof+v;
					}
					else if(rem>=0)
					{
						nof=nof+rem;
					}
					rem=-1;
				}
			}
			else
			{
				if(a[0][1]>=v)
				{
					nof=nof+v;
					rem=sum-v;
				}
				else
				{
					nof=nof+sum;
					rem=-1;
				}
			}
		}
		i=j-1;
	}
	if(rem>0)
	{
		if(rem<=v)
		nof=nof+rem;
		else
		nof=nof+v;
	}
	printf("%d\n",nof);
	return 0;
}


#include<stdio.h>
int main()
{
	int n,v,i,j,a[3001][2],k,temp,nof,sum=0,rem;
	scanf("%d%d",&n,&v);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&a[i][0],&a[i][1]);
	}
	for(i=0;i<n;i++)
	{
		for(j=i;j<n;j++)
		{
			if(a[i][0]>a[j][0])
			{
				temp=a[i][0];
				a[i][0]=a[j][0];
				a[j][0]=temp;
				temp=a[i][1];
				a[i][1]=a[j][1];
				a[j][1]=temp;
			}
		}
	}
	nof=0;
	for(i=0;i<n;i++)
	{
		sum=0;
		for(j=i;j<n&&a[i][0]==a[j][0];j++)
		{
			sum+=a[j][1];
		}
		printf("sum==%d\n",sum);
		if(sum>=v)
		{
			if(i>0)
			{
				//	printf("&&&\n");
				if(a[i][0]-a[i-1][0]==1)
				{
					if(rem>=0)
					{

						nof=nof+v;
						if(rem>=v)
						{
							rem=sum;
						}
						else
						{
							rem=sum+rem-v;
						}
					}
					else
					{
						nof=nof+v;
						rem=sum-v;
					}
				}
				else
				{
					nof=nof+v;
					rem=sum-v;
				}
			}
			else
			{
				nof=nof+v;
				rem=sum-v;
			}
		}
		else
		{
			if(i>0)
			{
				if(a[i][0]-a[i-1][0]==1)
				{
					if(rem>=0)
					{
						k=sum+rem;
						if(k>=v)
						{
							nof=nof+v;
							if(rem>=v)
							{
								rem=sum;
							}
						}
						else
						{
							nof=nof+k;
							rem=-1;
						}
					}
					else
					{
						nof=nof+sum;
						rem=-1;

					}
				}
				else
				{
					nof=nof+sum;
					rem=-1;
				}
			}
			else
			{
				if(a[0][1]>=v)
				{
					nof=nof+v;
					rem=a[0][1]-v;
				}
				else
				{
					nof=nof+a[0][1];
					rem=-1;
				}
			}
		}
		i=j-1;
		printf("nof==%d rem==%d\n",nof,rem);
	}
	if(rem>0)
	{
		if(rem<=v)
		nof=nof+rem;
		else
		nof=nof+v;
	}
	printf("%d\n",nof);
	return 0;
}


#include<stdio.h>
#include<string.h>

int fruit[3005];

int main()
{
	int tree,max,day,num,i,left,result ;
	while(scanf("%d%d",&tree,&max)!=EOF)
	{
		left = 0 ;
		result = 0 ;
		memset(fruit,0,sizeof(fruit));
		for(i=0;i<tree;i++)
		{
			scanf("%d%d",&day,&num);
			fruit[day] += num ;
		}
		for(i=1;i<3003;i++)
		{
			if(left>=max)
			{
				result += max ;
				left = fruit[i] ;
			}
			else if(left+fruit[i]>max)
			{
				result += max ;
				left = left+fruit[i]-max ;
			}
			else
			{
				result += fruit[i]+left ;
				left = 0 ;
			}
		}
		printf("%d\n",result);
	}
	return 0 ;
}


#include <stdio.h>
#include <stdlib.h>

#define MAX_A (3000)

int xs[MAX_A+1];

int min(int x, int y) { return x < y ? x : y; }

int main() {
  int a,b,i,n,v,b1,b2,acc;

  scanf("%d %d\n", &n, &v);
  for ( i=0; i < n; ++i ) {
    scanf("%d %d", &a, &b);
    xs[a] += b;
  }
  for ( i=1, acc=0; i <= MAX_A; ++i ) {
    b1 = min(v, xs[i-1]);
    xs[i-1] -= b1;
    b2 = min(v-b1, xs[i]);
    xs[i] -= b2;
    acc += b1 + b2;
  }
  printf("%d\n", acc);
  return EXIT_SUCCESS;
}


#include <stdio.h>
#include <stdlib.h>

#define MAX_A (3000)

int xs[MAX_A+2];

int min(int x, int y) { return x < y ? x : y; }

int main() {
  int a,b,i,n,v,b1,b2,acc;

  scanf("%d %d\n", &n, &v);
  for ( i=0; i < n; ++i ) {
    scanf("%d %d", &a, &b);
    xs[a] += b;
  }
  for ( i=1, acc=0; i <= MAX_A+1; ++i ) {
    b1 = min(v, xs[i-1]);
    xs[i-1] -= b1;
    b2 = min(v-b1, xs[i]);
    xs[i] -= b2;
    acc += b1 + b2;
  }
  printf("%d\n", acc);
  return EXIT_SUCCESS;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
int n, v, a, b, i;
scanf("%d %d", &n, &v);
int d[3002]={0};
for(i=0; i<n; i++)
{
    scanf("%d %d", &a, &b);
    d[a]+=b;
}
int cur=0, ans=0;
for(i=1; i<=3001; i++)
{
    if(d[i]+cur<=v)
    {
        ans+=d[i]+cur;
        cur=0;
    }
    else
    {
        ans+=v;
        cur=d[i]-(v-cur>0 ? v-cur : 0);
    }
    //printf("%d %d\n", ans, cur);
}
printf("%d\n", ans);
return 0;
}


#include <stdio.h>

int main(){
	int N[3003],v,i,n,k,tot=0,j,p,l,carry=0,m=0;
	scanf("%d %d",&n,&v);
	for(i=0;i<3003;++i)
		N[i]=0;
	for(i=0;i<n;++i){
		scanf("%d",&k);
		scanf("%d",&l);
		N[k-1]=N[k-1]+l;
		if(k>m) m=k;
	}
	for(i=0;i<m;++i){
		if(!carry){
			if(N[i]<=v) tot=tot+N[i];
			else{
				tot=tot+v;
				carry=N[i]-v;
			}
		}
		else{
			if(carry>v){
				tot=tot+v;
				carry=N[i];
			}
			else{
				if(carry+N[i]>v){
					tot=tot+v;
					carry=N[i]-(v-carry);
				}
				else{
					tot=carry+N[i];
					carry=0;
				}
			}
		}
	}
	if(carry){
		if(carry>v) tot=tot+v;
		else tot=tot+carry;
	}
	printf("%d",tot );
}


#include <stdio.h>

int main(){
	int N[3003],v,i,n,k,tot=0,j,p,l,carry=0;
	scanf("%d %d",&n,&v);
	for(i=0;i<3003;++i)
		N[i]=0;
	for(i=0;i<n;++i){
		scanf("%d",&k);
		scanf("%d",&l);
		N[k-1]=N[k-1]+l;
	}
	for(i=0;i<n;++i){
		if(!carry){
			if(N[i]<=v) tot=tot+N[i];
			else{
				tot=tot+v;
				carry=N[i]-v;
			}
		}
		else{
			if(carry>v){
				tot=tot+v;
				carry=N[i];
			}
			else{
				if(carry+N[i]>v){
					tot=tot+v;
					carry=N[i]-(v-carry);
				}
				else{
					tot=carry+N[i];
					carry=0;
				}
			}
		}
	}
	if(carry){
		if(carry>v) tot=tot+v;
		else tot=tot+carry;
	}
	printf("%d",tot );
}


#include <stdio.h>

int main(){
	int N[3003],v,i,n,k,tot=0,j,p,l,carry=0,m=0;
	scanf("%d %d",&n,&v);
	for(i=0;i<3003;++i)
		N[i]=0;
	for(i=0;i<n;++i){
		scanf("%d",&k);
		scanf("%d",&l);
		N[k-1]=N[k-1]+l;
		if(k>m) m=k;
	}
	for(i=0;i<m;++i){
		if(!carry){
			if(N[i]<=v) tot=tot+N[i];
			else{
				tot=tot+v;
				carry=N[i]-v;
			}
		}
		else{
			if(carry>v){
				tot=tot+v;
				carry=N[i];
			}
			else{
				if(carry+N[i]>v){
					tot=tot+v;
					carry=N[i]-(v-carry);
				}
				else{
					tot=tot+carry+N[i];
					carry=0;
				}
			}
		}
	}
	if(carry){
		if(carry>v) tot=tot+v;
		else tot=tot+carry;
	}
	printf("%d",tot);
	return 0;
}


#include <stdio.h>

int main(){
	int N[3003],v,i,n,k,tot=0,j,p,l,carry=0;
	scanf("%d %d",&n,&v);
	for(i=0;i<3003;++i)
		N[i]=0;
	for(i=0;i<n;++i){
		scanf("%d",&k);
		scanf("%d",&l);
		N[k-1]=N[k-1]+l;
	}
	for(i=0;i<3003;++i){
		if(!carry){
			if(N[i]<=v) tot=tot+N[i];
			else{
				tot=tot+v;
				carry=N[i]-v;
			}
		}
		else{
			if(carry>v){
				tot=tot+v;
				carry=N[i];
			}
			else{
				if(carry+N[i]>v){
					tot=tot+v;
					carry=N[i]-(v-carry);
				}
				else{
					tot=carry+N[i];
					carry=0;
				}
			}
		}
	}
	if(carry){
		if(carry>v) tot=tot+v;
		else tot=tot+carry;
	}
	printf("%d",tot );
}


#include <stdio.h>

int main(){
	int N[3003],v,i,n,k,tot=0,j,p,l,carry=0,m=0;
	scanf("%d %d",&n,&v);
	for(i=0;i<3003;++i)
		N[i]=0;
	for(i=0;i<n;++i){
		scanf("%d",&k);
		scanf("%d",&l);
		N[k-1]=N[k-1]+l;
		if(k>m) m=k;
	}
	for(i=0;i<m;++i){
		if(!carry){
			if(N[i]<=v) tot=tot+N[i];
			else{
				tot=tot+v;
				carry=N[i]-v;
			}
		}
		else{
			if(carry>v){
				tot=tot+v;
				carry=N[i];
			}
			else{
				if(carry+N[i]>v){
					tot=tot+v;
					carry=N[i]-(v-carry);
				}
				else{
					tot=tot+carry+N[i];
					carry=0;
				}
			}
		}
		printf("i=%d tot=%d\n carry=%d",i,tot,carry );
	}
	if(carry){
		if(carry>v) tot=tot+v;
		else tot=tot+carry;
	}
	printf("%d",tot);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

struct Tree
{
    int a,b;
};

int cmp(const void *x,const void *y)
{
    return ((*(struct Tree *)x).a-(*(struct Tree *)y).a);
}

int main()
{
    int n,v;
    while(scanf("%d%d",&n,&v)!=EOF)
    {
        int i,ans,maxday;
        int can[3005];
        struct Tree t[3005];
        maxday=0;
        memset(can,0,sizeof(can));
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&t[i].a,&t[i].b);
            if(t[i].a>maxday)
            {
                maxday=t[i].a;
            }
        }
        qsort(t+1,n,sizeof(t[1]),cmp);
        ans=0;
        for(i=1;i<=n;i++)
        {
            if(can[t[i].a]+t[i].b>v)
            {
                can[t[i].a+1]=can[t[i].a]+t[i].b-v;
                can[t[i].a]=v;
            }
            else
            {
                can[t[i].a]+=t[i].b;
            }
        }
        for(i=1;i<=maxday+1;i++)
        {
            ans+=((can[i]<=v)?can[i]:v);
        }
        printf("%d\n",ans);
    }
    return (0);
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

struct Tree
{
    int a,b;
};

int cmp(const void *x,const void *y)
{
    return ((*(struct Tree *)x).a-(*(struct Tree *)y).a);
}

int MyMin(int a,int b)
{
    return (a<b?a:b);
}

int main()
{
    int n,v;
    while(scanf("%d%d",&n,&v)!=EOF)
    {
        int i,ans,maxday;
        int can[3005];
        struct Tree t[3005];
        maxday=0;
        memset(can,0,sizeof(can));
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&t[i].a,&t[i].b);
            if(t[i].a>maxday)
            {
                maxday=t[i].a;
            }
        }
        qsort(t+1,n,sizeof(t[1]),cmp);
        ans=0;
        for(i=1;i<=n;i++)
        {
            can[t[i].a]+=t[i].b;
            if(can[t[i].a]>v)
            {
                can[t[i].a+1]=can[t[i].a]-v;
                can[t[i].a]=v;
            }
        }
        for(i=1;i<=maxday+1;i++)
        {
            ans+=MyMin(can[i],v);
        }
        printf("%d\n",ans);
    }
    return (0);
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

struct Tree
{
    int a,b;
};

int cmp(const void *x,const void *y)
{
    return ((*(struct Tree *)x).a-(*(struct Tree *)y).a);
}

int MyMin(int a,int b)
{
    return (a<b?a:b);
}

int main()
{
    int n,v;
    while(scanf("%d%d",&n,&v)!=EOF)
    {
        int i,ans,maxday;
        int can[3005];
        struct Tree t[3005];
        maxday=0;
        memset(can,0,sizeof(can));
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&t[i].a,&t[i].b);
            if(t[i].a>maxday)
            {
                maxday=t[i].a;
            }
        }
        qsort(t+1,n,sizeof(t[1]),cmp);
        ans=0;
        for(i=1;i<=maxday;i++)
        {
            can[i]+=t[i].b;
            if(can[i]>v)
            {
                can[i+1]=can[i]-v;
                can[i]=v;
            }
        }
        for(i=1;i<=maxday+1;i++)
        {
            ans+=MyMin(can[i],v);
        }
        printf("%d\n",ans);
    }
    return (0);
}