#include <iostream>

using namespace std;

int main()
{
  int N, M;
  int max_v[101];
  int sum;
  
  while (1) {
    cin >> N >> M;
    if (N == 0 && M == 0) break;

    for (int& v : max_v) v = 0;

    while (N--) {
      int d, v;
      cin >> d >> v;
      if (v > max_v[d]) max_v[d] = v;
    }

    sum = 0;
    for (int i = 1; i <= M; i++) {
      sum += max_v[i];
    }
    cout << sum << endl;
  }
}
      
    

