#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  while (cin >> N >> M, N) {
    auto a = vector<int>(M + 1, 0);
    for (int i = 0; i < N; ++i) {
      int d, v; cin >> d >> v;
      a[d] = max(a[d], v);
    }
    int ans = accumulate(begin(a), end(a), 0);
    cout << ans << endl;
  }
  return 0;
}

