#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	int n,m;
	while(1){
		cin>>n>>m;
		if(n==0)break;
		vector<int> d(n),v(n);
		vector<int> val(m,0);
		for(int i=0;i<n;i++){
			cin>>d[i]>>v[i];
			val[d[i]-1] = max(val[d[i]-1] , v[i]);
		}
		int sum = 0;
		for(int i=0;i<m;i++)sum+= val[i];
		cout<<sum<<endl;

	}
	return 0;
}

