#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
signed main() {
  int N, M;
  while (cin >> N >> M, N+M) {
    vector<int> maxV(M, 0);
    for (int i = 0; i < N; i++) {
      int d, v;
      cin >> d >> v;
      maxV[d-1] = max(maxV[d-1], v);
    }
    int ans = 0;
    for (int i = 0; i < M; i++) {
      ans += maxV[i];
    }
    cout << ans << endl;
  }  
}

