#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx,tune=naive")
//#pragma GCC diagnostic ignored "-W"
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define ll long long
#define INF 2000000000
#define PI 3.1415926535897932384626
const ll MOD=1e9+7;
pii jobs[100005];
int a[100005],b[100005];
struct seg{
        int maxV,id;
        seg *l,*r;
        void pull(){
                maxV=max(l->maxV,r->maxV);
                if(l->maxV==r->maxV){
                        if(a[l->id]>a[r->id]) id=l->id;
                        else id=r->id;
                        return;
                }
                if(l->maxV>r->maxV) id=l->id;
                else id=r->id;
        }
};
seg* build(int l,int r){
        seg *child=new seg();
        if(l==r){
                child->maxV=b[l];
                child->id=l;
                child->l=child->r=NULL;
                return child;
        }
        int mid=(l+r)/2;
        child->l=build(l,mid);
        child->r=build(mid+1,r);
        child->pull();
        return child;
}
pii query(int l,int r,int L,int R,seg *now){
        if(l<L||r>R) assert(0);
        if(l==L&&r==R) return mp(now->maxV,now->id);
        int mid=(L+R)/2;
        if(l>mid) return query(l,r,mid+1,R,now->r);
        if(r<=mid) return query(l,r,L,mid,now->l);
        pii left=query(l,mid,L,mid,now->l);
        pii right=query(mid+1,r,mid+1,R,now->r);
        if(left.f==right.f){
                if(a[left.s]>a[right.s]) return left;
                return right;
        }
        if(left.f>right.f) return left;
        return right;
}
void add(int id,int v,int L,int R,seg *now){
        if(L==id&&R==id){
                now->maxV=v;
                return;
        }
        int mid=(L+R)/2;
        if(id<=mid) add(id,v,L,mid,now->l);
        else add(id,v,mid+1,R,now->r);
        now->pull();
}
int main(){
        int n,m;
        while(~getII(n,m)){
                F(i,0,n) getII(jobs[i].f,jobs[i].s);
                sort(jobs,jobs+n);
                F(i,0,n) a[i]=jobs[i].f,b[i]=jobs[i].s;
                //a=after a days, b=$
                seg *root=build(0,n-1);//build seg tree on a
                int ans=0;
                for(int i=m-1;i>=0;i--){
                        int left=m-i;
                        int j=upper_bound(a,a+n,left)-a-1;
                        if(j<0) continue;
//                      printf("left:%d j:%d\n",left,j);
                        pii q=query(0,j,0,n-1,root);
//                      printf("left:%d max[0,%d]=%d id=%d\n",left,j,q.f,q.s);
                        if(q.f>0){
                                ans+=q.f;//q.f=max b, q.s=max b's index
                                //when two jobs have the same $, pick the one that has smaller a
                                add(q.s,0,0,n-1,root);
                        }
                }
                printf("%d\n",ans);
        }
}


Measured memory_bytes: 8064