#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

template<class T>
void maxi(T &a, const T &b){
  if(a < b) a = b;
}

int n,m;
int va[112];

void solve() {
  int vs = 0;
  for(int i = 1; i <= m; ++i){
    vs += va[i];
  }
  cout << vs << endl;
}

int main(int argc, char *argv[]){

  /*Regular*/
  // if (argc > 1 && stoi(argv[1])) cin >> case_num;
  // REP(case_no, case_num) {
  //   cerr << endl << "case " << case_no + 1 << endl;
  //   solve();
  // }

  /*ICPC*/
  while (cin >> n >> m, n && m) {
    REP(i, n){
      int d, v;
      cin >> d >> v;
      maxi(va[d], v);
    }
    solve();
    for(int i = 1; i <= m; ++i) va[i] = 0;
  }

  return 0;
}
