// Charan Sriramula
 
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;
 
const ll logx=30;
const ll N=1e5+5;
const ll INF=1e18+5;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;
 
#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%intd",&n)
#define longp(n) printf("%intd\n",n)
 
inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
 
#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1ll;x=(x*x)%m;}return ans%m;}
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

struct node
{
  ll val;
  ll idx;
};

ll n,m;
node seg[4*N];
pair<ll,pair<ll,ll> > p[N];

node combine(node l,node r)
{
  node cur;
  cur.idx=r.idx;
  cur.val=max(l.val,r.val);
  if(l.val>r.val)
  {
    cur.idx=l.idx;
  }
  return cur;
}

void build(ll low,ll high,ll pos)
{
  if(low==high)
  {
    seg[pos].val=p[low].s.f;
    seg[pos].idx=low;
    return;
  }
  ll mid=(low+high)/2;
  build(low,mid,2*pos+1);
  build(mid+1,high,2*pos+2);
  seg[pos]=combine(seg[2*pos+1],seg[2*pos+2]);
}

void update(ll low,ll high,ll qpos,ll pos)
{
  if(low==high)
  {
    seg[pos].val=-1;
    return;
  }
  else
  {
    ll mid=(low+high)/2;
    if(low<=qpos&&qpos<=mid) update(low,mid,qpos,2*pos+1);
    else update(mid+1,high,qpos,2*pos+2);
    seg[pos]=combine(seg[2*pos+1],seg[2*pos+2]);
  }
}

node query(ll low,ll high,ll qlow,ll qhigh,ll pos)
{
  if(qlow>high||qhigh<low) return {0,0};
  if(qlow<=low&&qhigh>=high) return seg[pos];
  ll mid=(low+high)/2;
  return combine(query(low,mid,qlow,qhigh,2*pos+1),query(mid+1,high,qlow,qhigh,2*pos+2));
}

int main()
{
  //ll n,m;
  cin>>n>>m;
  //pair<ll,ll> p[n];
  for(ll i=0;i<n;i++){cin>>p[i].f>>p[i].s.f;p[i].s.s=i;}
  sort(p,p+n);
  vector<ll> v;
  ll sum=0;
  build(0,n-1,0);
  for(ll i=0;i<n;i++){v.pb(p[i].f);}
  //for(ll i=0;i<n;i++){trace3(i,p[i].f,p[i].s.f);}
  for(ll i=m;i>=1;i--)
  {
    ll cur=m-i+1;
    ll ub=upper_bound(all(v),cur)-v.begin();
    ub--;
    if(ub<0){continue;}
    node ans=query(0,n-1,0,ub,0);
    sum+=ans.val;
    update(0,n-1,ans.idx,0);
    //trace5(i,cur,ub,ans.val,ans.idx);
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 9592