#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N, M;
    while(true){
        cin >> N >> M;
        if(N == 0) break;
        vector<priority_queue<int>> pq(M);
        rep(i, N){
            int d, v; cin >> d >> v;
            pq[d-1].push(v);
        }
        int acc = 0;
        rep(i, M) acc += pq[i].top();
        cout << acc << endl;
    }
    return 0;
}
