/**
 *   author: malviyanshiv
 *   created: 10 August 2019  17:46:06
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define FORE(a) for(auto ele : a )
#define ALL(a) begin(a), end(a)
#define RPB(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define F first
#define S second
#define TC int t; cin >> t; while(t--)
#define SET(a,b) memset(a,b,sizeof(a))

#define TRACE

#ifdef TRACE
#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;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

#define MAX 100005

typedef long long ll;
typedef pair< int, int > PII;


void optimizeIO(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
}

vector<int> tree(4*MAX, 0);
vector<int> treedx(4*MAX, -1);

void insert(int idx, int l, int r, int n, int val){
    if( l == r ){
        //trace5(idx, l, r, n, val);
        tree[idx] = val;
        treedx[idx] = n;
        return;
    }
    int md = (l+r)/2;
    if( n <= md )
        insert(2*idx, l, md, n, val);
    else
        insert(2*idx+1, md+1, r, n, val);

    if(tree[2*idx] > tree[2*idx+1]){
        tree[idx] = tree[2*idx];
        treedx[idx] = treedx[2*idx];
    }else{
        tree[idx] = tree[2*idx+1];
        treedx[idx] = treedx[2*idx+1];
    }
}

void erase(int idx, int l, int r, int n){
    if( l == r ){
        tree[idx] = 0;
        treedx[idx] = -1;
        return;
    }
    int md = (l+r)/2;
    if( n <= md )
        erase(2*idx, l, md, n);
    else
        erase(2*idx+1, md+1, r, n);

    if(tree[2*idx] > tree[2*idx+1]){
        tree[idx] = tree[2*idx];
        treedx[idx] = treedx[2*idx];
    }else{
        tree[idx] = tree[2*idx+1];
        treedx[idx] = treedx[2*idx+1];
    }
}

int main(){
    optimizeIO();

    int n, m, a, b;
    cin >> n >> m;
    vector<pair<int, int>> arr(n);
    REP(i, 0, n)
        cin >> arr[i].F >> arr[i].S;
    sort(arr.begin(), arr.end());
    vector<ll> work(m+1, 0);
    int ls = -1, idx = 0;
    REP(i, 1, m+1){
        while(idx < n && arr[idx].F <= i){
            insert(1, 0, n, ls+1, arr[idx].S);
            idx++, ls++;
        }
        if(tree[1]){
            //trace4("dele", treedx[1], tree[1], i);
            work[i] = tree[1];
            erase(1, 0, n, treedx[1]);
            //trace4("after", treedx[1], tree[i], i);
        }
    }

    ll sm = 0;
    REP(i, 1, m+1)
        sm += work[i];
    cout << sm;
    
    return 0;
}

Measured memory_bytes: 4992