// OURL: https://atcoder.jp/contests/abc137/tasks/abc137_d
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res;}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ipair = std::pair<int, int>;
using jpair = std::pair<int, int>;

// bool operator> (const ipair a, const ipair b){
//   if (a.first != b.first) return a.first > b.first;
//   else return a.second > b.second;
// };
// bool operator< (const jpair a, const jpair b){return a.second > b.second;};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m;
  cin >> n >> m;

  priority_queue<ipair, vector<ipair>, greater<ipair>> pre_jobs;
  priority_queue<int, vector<int>, greater<int>> post_jobs;

  pre_jobs.emplace(100001, 0);
  REP(i,n) {
    int a,b;
    cin >> a >> b;
    // debug(a,b*-1);
    if (a <= m) {
      pre_jobs.emplace(a,b*-1);
    }
  }
  post_jobs.emplace(0);

  // debug(pre_jobs);
  // 
  // while(!pre_jobs.empty()) {
  //       auto tmp = pre_jobs.top();
  //       debug(tmp);
  //       // pre_jobs.emplace(tmp.first, tmp.second);
  //       pre_jobs.pop();
  // }
  // return 0;

  ll sum = 0;
  int t = 1;
  while(t <= m && !(post_jobs.empty() && pre_jobs.empty())){
        auto pre = pre_jobs.top();
        auto post = post_jobs.top();
        debug(t, pre, post);
        if (pre.first > t) {
          if (post < 0) {
            sum -= post;
            post_jobs.pop();
          }
        } else {
          if (pre.second < post) {
            sum -= pre.second;
          } else {
            sum -= post;
            post_jobs.pop();
            post_jobs.emplace(pre.second);
          }
          // int tt = pre.first;
          while (!pre_jobs.empty()) {
            pre_jobs.pop();
            pre = pre_jobs.top();
            if (pre.first > t) break;
            post_jobs.emplace(pre.second);
          }
        }
        t++;
        // debug(tmp);
        // post_jobs.emplace(tmp.second);
        // pre_jobs.pop();
  }

  cout << sum << endl;

  debug(pre_jobs.size(), post_jobs.size());

  return 0;
}




Measured memory_bytes: 1908