#include <iostream>

using namespace std;

int N, M;
int maxv[105];

int main(void)
{
	while(1){
		cin >> N >> M;
		if( N == 0 && M == 0 ) break;
		
		for(int i = 1; i <= M; i++) maxv[i] = 0;
		
		int d, v;
		for(int i = 0; i < N; i++){
			cin >> d >> v;
			maxv[d] = max(maxv[d], v);
		}
		int ans = 0;
		for(int i = 1; i <= M; i++) ans += maxv[i];
		cout << ans << endl;
	}
	return 0;
}
