#include <iostream>
using namespace std;

int main(){
  int n,m;
  int d[100] = {};
  int v[100] = {};
  int count[100] = {0};
  int n_count = 0;

  while(cin >> n >> m){
    if(m == 0 && n == 0){ break; }

    for(int i = 0; i < n; i++){
    cin >> d[i] >> v[i];
    }

    for(int j = 1; j <= m; j++){
      int max = 0;
      for(int t = 0; t < n; t++){
        if(d[t] == j && v[t] > max) max = v[t];
      }
      count[n_count] += max;
    }
    n_count++;
  }

  for(int x = 0; x < n_count; x++){
    cout << count[x] << endl;
  }

  return 0;
}